/* ============================================================
   Прикладной анализ поведения — учебный справочник
   Стили: светлая/тёмная тема, типографика, блоки, печать
   ============================================================ */

/* ---------- Тема: переменные ---------- */

:root,
:root[data-theme="light"] {
  --bg: #fbfaf7;
  --bg-elev: #ffffff;
  --bg-sunken: #f1efe9;
  --fg: #1a1c20;
  --fg-soft: #3d434d;
  --muted: #5f6875;
  --line: #d8dce2;
  --line-strong: #b9c0ca;
  --accent: #1a5fb4;
  --accent-fg: #ffffff;
  --accent-soft: #e7effa;
  --book: #1a5fb4;
  --book-bg: #eef4fc;
  --quote: #6b4f9e;
  --quote-bg: #f4f0fb;
  --example: #1f6b45;
  --example-bg: #ecf7f0;
  --me: #8a4b12;
  --me-bg: #fdf2e6;
  --extra: #8a6d00;
  --extra-bg: #fdf8e3;
  --task: #0f6b6b;
  --task-bg: #e8f6f6;
  --warn: #a01b30;
  --warn-bg: #fdecef;
  --shadow: 0 1px 2px rgba(20, 25, 35, .06), 0 8px 24px rgba(20, 25, 35, .05);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121417;
    --bg-elev: #191c21;
    --bg-sunken: #0e1013;
    --fg: #e6e9ee;
    --fg-soft: #c3c9d3;
    --muted: #98a2b0;
    --line: #2a2f38;
    --line-strong: #3b4250;
    --accent: #79aefb;
    --accent-fg: #0b1220;
    --accent-soft: #1b2739;
    --book: #79aefb;
    --book-bg: #16202e;
    --quote: #b39cf0;
    --quote-bg: #201b2e;
    --example: #6fd39b;
    --example-bg: #14251c;
    --me: #e2a56a;
    --me-bg: #2a1f14;
    --extra: #dcc35c;
    --extra-bg: #26220f;
    --task: #5fd0d0;
    --task-bg: #102424;
    --warn: #ff8a9b;
    --warn-bg: #2c151a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #121417;
  --bg-elev: #191c21;
  --bg-sunken: #0e1013;
  --fg: #e6e9ee;
  --fg-soft: #c3c9d3;
  --muted: #98a2b0;
  --line: #2a2f38;
  --line-strong: #3b4250;
  --accent: #79aefb;
  --accent-fg: #0b1220;
  --accent-soft: #1b2739;
  --book: #79aefb;
  --book-bg: #16202e;
  --quote: #b39cf0;
  --quote-bg: #201b2e;
  --example: #6fd39b;
  --example-bg: #14251c;
  --me: #e2a56a;
  --me-bg: #2a1f14;
  --extra: #dcc35c;
  --extra-bg: #26220f;
  --task: #5fd0d0;
  --task-bg: #102424;
  --warn: #ff8a9b;
  --warn-bg: #2c151a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

/* ---------- База ---------- */

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

/* Якоря не должны прятаться под липкой панелью */
[id] { scroll-margin-top: 5.2rem; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 400 clamp(16px, 1.5vw, 17.5px)/1.62 "Segoe UI", "PT Sans", -apple-system, BlinkMacSystemFont, Roboto, Arial, sans-serif;
  text-rendering: optimizeLegibility;
}

.wrap {
  width: min(100% - 2.5rem, 74rem);
  margin-inline: auto;
}

@media (max-width: 640px) {
  .wrap { width: min(100% - 1.6rem, 74rem); }
}

a { color: var(--accent); text-underline-offset: .18em; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-fg);
  padding: .6rem 1rem;
  z-index: 100;
  border-radius: 0 0 8px 0;
}
.skip:focus { left: 0; }

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar__row {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-height: 3.5rem;
  flex-wrap: wrap;
}

.brand {
  font-weight: 700;
  letter-spacing: .01em;
  color: var(--fg);
  text-decoration: none;
  white-space: nowrap;
}
.brand span { color: var(--accent); }

.topnav {
  display: flex;
  gap: .25rem;
  flex: 1 1 auto;
  flex-wrap: wrap;
}
.topnav a {
  color: var(--fg-soft);
  text-decoration: none;
  padding: .35rem .55rem;
  border-radius: 8px;
  font-size: .93rem;
}
.topnav a:hover { background: var(--bg-sunken); color: var(--fg); }
.topnav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.tools { display: flex; gap: .4rem; margin-left: auto; }

.btn {
  font: inherit;
  font-size: .9rem;
  padding: .45rem .8rem;
  border-radius: 9px;
  border: 1px solid var(--line-strong);
  background: var(--bg-elev);
  color: var(--fg);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  line-height: 1.2;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn--primary:hover { color: var(--accent-fg); filter: brightness(1.08); }
a.btn { text-decoration: none; }

/* ---------- Поиск ---------- */

.searchpanel {
  border-top: 1px solid var(--line);
  padding: .9rem 0 1.1rem;
  background: var(--bg);
}
.searchpanel[hidden] { display: none; }

.searchfield {
  display: flex;
  gap: .5rem;
  align-items: center;
}
.searchfield input {
  font: inherit;
  flex: 1 1 auto;
  padding: .6rem .8rem;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--bg-elev);
  color: var(--fg);
}
.searchhint { color: var(--muted); font-size: .84rem; margin: .5rem 0 0; }

.searchresults {
  margin: .6rem 0 0;
  padding: 0;
  list-style: none;
  max-height: 52vh;
  overflow: auto;
}
.searchresults li { border-bottom: 1px solid var(--line); }
.searchresults a {
  display: block;
  padding: .6rem .3rem;
  text-decoration: none;
  color: inherit;
  border-radius: 8px;
}
.searchresults a:hover { background: var(--bg-sunken); }
.searchresults b { display: block; color: var(--accent); font-weight: 600; }
.searchresults small { color: var(--muted); }
.searchempty { color: var(--muted); padding: .6rem .2rem; }

/* ---------- Основной контент ---------- */

main { padding: 2rem 0 4rem; }

.crumbs {
  font-size: .85rem;
  color: var(--muted);
  margin: 0 0 1.2rem;
}
.crumbs a { color: var(--muted); }
.crumbs span { opacity: .6; margin: 0 .4rem; }

.eyebrow {
  text-transform: uppercase;
  letter-spacing: .09em;
  font-size: .74rem;
  font-weight: 700;
  color: var(--accent);
  margin: 0 0 .5rem;
}

h1, h2, h3, h4 {
  line-height: 1.25;
  color: var(--fg);
  margin: 2.2rem 0 .8rem;
  font-weight: 700;
}
h1 { font-size: clamp(1.7rem, 3.4vw, 2.5rem); margin-top: .4rem; letter-spacing: -.01em; }
h2 { font-size: clamp(1.3rem, 2.2vw, 1.65rem); border-top: 1px solid var(--line); padding-top: 1.4rem; }
h3 { font-size: 1.15rem; }
h4 { font-size: 1rem; margin: 1.4rem 0 .5rem; }

.lead {
  font-size: 1.1rem;
  color: var(--fg-soft);
  max-width: 68ch;
}

p { margin: 0 0 1rem; max-width: 72ch; }
ul, ol { margin: 0 0 1rem; padding-left: 1.35rem; max-width: 72ch; }
li { margin: .3rem 0; }
li > ul, li > ol { margin-top: .35rem; }

strong { font-weight: 700; }
em { font-style: italic; }

code, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .92em; }

hr { border: 0; border-top: 1px solid var(--line); margin: 2rem 0; }

/* ---------- Термины ---------- */

.term {
  font-weight: 650;
  color: var(--fg);
  border-bottom: 1px dotted var(--line-strong);
  cursor: help;
}
.orig {
  font-style: italic;
  font-weight: 400;
  color: var(--muted);
  font-size: .95em;
}

/* ---------- Блоки-ярлыки ---------- */

.block {
  position: relative;
  margin: 1.5rem 0;
  padding: 1rem 1.1rem 1rem 1.15rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  border-left: 4px solid var(--line-strong);
  background: var(--bg-elev);
  max-width: 74ch;
}
.block > :last-child { margin-bottom: 0; }
.block > .lbl {
  display: inline-block;
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .07em;
  text-transform: uppercase;
  margin: 0 0 .55rem;
  padding: .16rem .45rem;
  border-radius: 5px;
  background: var(--bg-sunken);
  color: var(--muted);
}

.b-book { border-left-color: var(--book); background: var(--book-bg); }
.b-book > .lbl { background: color-mix(in srgb, var(--book) 16%, transparent); color: var(--book); }

.b-quote { border-left-color: var(--quote); background: var(--quote-bg); }
.b-quote > .lbl { background: color-mix(in srgb, var(--quote) 16%, transparent); color: var(--quote); }
.b-quote blockquote {
  margin: 0;
  font-style: italic;
  color: var(--fg-soft);
}
.b-quote cite {
  display: block;
  margin-top: .5rem;
  font-size: .85rem;
  font-style: normal;
  color: var(--muted);
}

.b-example { border-left-color: var(--example); background: var(--example-bg); }
.b-example > .lbl { background: color-mix(in srgb, var(--example) 16%, transparent); color: var(--example); }

.b-me { border-left-color: var(--me); background: var(--me-bg); }
.b-me > .lbl { background: color-mix(in srgb, var(--me) 16%, transparent); color: var(--me); }

.b-extra { border-left-color: var(--extra); background: var(--extra-bg); }
.b-extra > .lbl { background: color-mix(in srgb, var(--extra) 18%, transparent); color: var(--extra); }

.b-task { border-left-color: var(--task); background: var(--task-bg); }
.b-task > .lbl { background: color-mix(in srgb, var(--task) 16%, transparent); color: var(--task); }

.b-warn { border-left-color: var(--warn); background: var(--warn-bg); }
.b-warn > .lbl { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }

/* ---------- Определение ---------- */

.definition {
  margin: 1.4rem 0;
  padding: 1.1rem 1.2rem;
  border-radius: var(--radius);
  background: var(--bg-elev);
  border: 1px solid var(--line-strong);
  border-top: 4px solid var(--accent);
  max-width: 74ch;
  box-shadow: var(--shadow);
}
.definition .dt {
  font-weight: 750;
  font-size: 1.05rem;
  margin: 0 0 .4rem;
}
.definition p:last-child { margin-bottom: 0; }

/* ---------- Сноска-источник ---------- */

.source {
  font-size: .82rem;
  color: var(--muted);
  border-top: 1px dashed var(--line-strong);
  margin: 1.6rem 0 0;
  padding-top: .6rem;
  max-width: 74ch;
}
.source b { color: var(--fg-soft); font-weight: 600; }

/* ---------- Таблицы ---------- */

.tablewrap { overflow-x: auto; margin: 1.2rem 0; max-width: 100%; }
table {
  border-collapse: collapse;
  width: 100%;
  font-size: .93rem;
  background: var(--bg-elev);
}
caption {
  caption-side: top;
  text-align: left;
  color: var(--muted);
  font-size: .85rem;
  padding: 0 0 .5rem;
}
th, td {
  border: 1px solid var(--line);
  padding: .5rem .65rem;
  vertical-align: top;
  text-align: left;
}
th { background: var(--bg-sunken); font-weight: 650; }

/* ---------- Карточки на главной и в оглавлении ---------- */

.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 17rem), 1fr));
  margin: 1.4rem 0;
}

.card {
  display: flex;
  flex-direction: column;
  gap: .4rem;
  padding: 1rem 1.05rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
  text-decoration: none;
  color: inherit;
  transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--accent); }
.card .num {
  font-size: .75rem;
  font-weight: 800;
  letter-spacing: .08em;
  color: var(--accent);
  text-transform: uppercase;
}
.card h3 { margin: 0; font-size: 1.02rem; }
.card p { margin: 0; font-size: .88rem; color: var(--muted); max-width: none; }
.card .meta { margin-top: auto; font-size: .78rem; color: var(--muted); }

/* ---------- Оглавление по частям ---------- */

.part {
  margin: 2.4rem 0 0;
  padding-top: .2rem;
}
.part__head {
  display: flex;
  align-items: baseline;
  gap: .7rem;
  border-bottom: 2px solid var(--line-strong);
  padding-bottom: .4rem;
  margin-bottom: .8rem;
}
.part__head h2 { border: 0; margin: 0; padding: 0; font-size: 1.18rem; }
.part__head span { color: var(--muted); font-size: .8rem; margin-left: auto; }

.chapterlist { list-style: none; padding: 0; margin: 0; }
.chapterlist > li {
  border-bottom: 1px solid var(--line);
  padding: .7rem 0;
}
.chapterlist .ch {
  display: flex;
  gap: .7rem;
  align-items: baseline;
  text-decoration: none;
  color: inherit;
  font-weight: 600;
}
.chapterlist .ch .n {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  min-width: 2.2rem;
}
.chapterlist .ch .pg { color: var(--muted); font-weight: 400; font-size: .82rem; margin-left: auto; text-align: right; }
.chapterlist .ch.is-planned { color: var(--muted); font-weight: 400; }
.chapterlist .ch.is-planned .n { color: var(--muted); }
.chapterlist .ch .pg .tag { font-weight: 600; }
.lessonlist { list-style: none; margin: .4rem 0 0; padding: 0 0 0 2.9rem; }
.lessonlist li { display: flex; gap: .5rem; align-items: baseline; font-size: .9rem; }
.lessonlist a { text-decoration: none; }
.lessonlist a:hover { text-decoration: underline; }
.done-dot {
  width: .5rem; height: .5rem; border-radius: 50%;
  border: 1.5px solid var(--line-strong);
  display: inline-block; flex: 0 0 auto;
}
.done-dot.is-done { background: var(--example); border-color: var(--example); }

/* ---------- Прогресс ---------- */

.progressbox {
  display: flex;
  align-items: center;
  gap: .9rem;
  flex-wrap: wrap;
  padding: .9rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
  margin: 1.2rem 0;
  max-width: 74ch;
}
.progressbar {
  flex: 1 1 12rem;
  height: .55rem;
  background: var(--bg-sunken);
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.progressbar > i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 99px;
  transition: width .25s;
}
.progressbox .txt { font-size: .88rem; color: var(--fg-soft); }

/* ---------- Самопроверка ---------- */

.quiz { counter-reset: q; margin: 1.2rem 0; max-width: 74ch; }
.quiz details {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-elev);
  margin: 0 0 .6rem;
  padding: .75rem .9rem;
}
.quiz details[open] { border-color: var(--accent); }
.quiz summary {
  cursor: pointer;
  font-weight: 600;
  list-style: none;
  display: flex;
  gap: .6rem;
  align-items: baseline;
}
.quiz summary::-webkit-details-marker { display: none; }
.quiz summary::before {
  counter-increment: q;
  content: "Вопрос " counter(q);
  flex: 0 0 auto;
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--task);
  padding-top: .2rem;
}
.quiz .answer {
  margin: .7rem 0 0;
  padding-top: .7rem;
  border-top: 1px dashed var(--line-strong);
  font-size: .95rem;
}
.quiz .answer p:last-child { margin-bottom: 0; }

/* ---------- Навигация уроков ---------- */

.pager {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin: 2.6rem 0 0;
  padding-top: 1.2rem;
  border-top: 1px solid var(--line);
}
.pager a {
  text-decoration: none;
  padding: .6rem .9rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-elev);
  font-size: .9rem;
  max-width: 22rem;
}
.pager a:hover { border-color: var(--accent); }
.pager .dir { display: block; font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }

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

footer {
  border-top: 1px solid var(--line);
  padding: 1.6rem 0 2.4rem;
  color: var(--muted);
  font-size: .85rem;
}
footer p { max-width: 74ch; }

/* ---------- Утилиты ---------- */

.muted { color: var(--muted); }
.small { font-size: .88rem; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.mt0 { margin-top: 0; }
.mb0 { margin-bottom: 0; }
.list-tight li { margin: .15rem 0; }

.tag {
  display: inline-block;
  font-size: .74rem;
  padding: .12rem .45rem;
  border-radius: 5px;
  background: var(--bg-sunken);
  color: var(--muted);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.tag--ok { background: var(--example-bg); color: var(--example); border-color: transparent; }
.tag--warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }

/* ---------- Печать ---------- */

@media print {
  :root { --bg: #fff; --bg-elev: #fff; --fg: #000; --fg-soft: #111; --muted: #444; --line: #bbb; }
  .topbar, .pager, footer .noprint, .skip, .tools, .searchpanel { display: none !important; }
  body { font-size: 11pt; }
  main { padding: 0; }
  .block, .definition, .card, .quiz details { break-inside: avoid; }
  h1, h2, h3 { break-after: avoid; }
  a { color: #000; text-decoration: underline; }
  .quiz details { border: 1px solid #999; }
  .quiz .answer { display: block !important; }
}
