/*
 * Components of a prep.html fragment (contract: CONTENT.md, «Component classes»). Everything is scoped to .prose,
 * the article that wraps the fragment, so the same classes can be used by the future editor preview.
 */

.prose {
  min-width: 0;
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  overflow-wrap: break-word;
}
.prose :is(h2, h3, h4, .q, [id]) {
  scroll-margin-top: var(--anchor-offset, 96px);
}
.prose > :first-child {
  margin-top: 0;
}
.prose h2 {
  margin: var(--space-12) 0 var(--space-4);
  font-family: var(--font-head);
  font-size: 19px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}
@media (min-width: 640px) {
  .prose h2 {
    font-size: 21px;
  }
}
/* «Изменить» after a section title: the owner only (server-side). Shown on hover or focus where there is a mouse,
   always (icon only) on touch screens; never in print. */
.prose h2 .h2-edit {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  gap: 4px;
  margin-left: var(--space-2);
  padding: 0 var(--space-2);
  border-radius: var(--radius-full);
  font-family: var(--font-body, inherit);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1;
  color: var(--gray-500);
  text-decoration: none;
  vertical-align: 2px;
  white-space: nowrap;
  transition: opacity 150ms var(--ease-out-soft), background-color 150ms var(--ease-out-soft), color 150ms var(--ease-out-soft);
}
.prose h2 .h2-edit:hover {
  background: var(--gray-100);
  color: var(--gray-900);
}
.prose h2 .h2-edit:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
@media (hover: hover) and (pointer: fine) {
  .prose h2 .h2-edit {
    opacity: 0;
  }
  .prose h2:hover .h2-edit,
  .prose h2 .h2-edit:focus-visible {
    opacity: 1;
  }
}
/* Touch: a 44 px target that hangs 4 px above and below the heading's line, so the title does not grow. */
@media (hover: none), (pointer: coarse) {
  .prose h2 .h2-edit {
    min-width: 44px;
    min-height: 44px;
    justify-content: center;
    margin-block: -4px;
    margin-left: 0;
    padding: 0;
    vertical-align: middle;
  }
  .prose h2 .h2-edit__text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
}
@media print {
  .prose h2 .h2-edit {
    display: none;
  }
}
.prose h3 {
  margin: var(--space-8) 0 var(--space-2);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.4;
}
.prose h4 {
  margin: var(--space-6) 0 var(--space-2);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
}
.prose p {
  margin: 0 0 var(--space-3);
}
.prose ul,
.prose ol {
  margin: 0 0 var(--space-3);
  padding-left: 22px;
}
.prose li {
  margin: var(--space-1) 0;
}
.prose li > ul,
.prose li > ol {
  margin: var(--space-1) 0 0;
}
.prose a {
  color: var(--brand-600);
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in srgb, var(--brand-600) 40%, transparent);
  text-underline-offset: 3px;
}
.prose a:hover {
  text-decoration-color: currentColor;
}
.prose b,
.prose strong {
  font-weight: 650;
}
.prose code {
  padding: 1px 6px;
  border-radius: var(--radius-xs);
  background: var(--gray-100);
  font-family: var(--font-mono);
  font-size: 0.88em;
  overflow-wrap: anywhere;
}
.prose pre {
  margin: 0 0 var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  background: var(--gray-50);
  overflow-x: auto;
  font-size: 14px;
  line-height: 1.55;
}
.prose pre code {
  padding: 0;
  background: none;
  overflow-wrap: normal;
}
.prose img {
  height: auto;
  border-radius: var(--radius-lg);
}
.prose hr {
  margin: var(--space-8) 0;
  border: 0;
  border-top: 1px solid var(--gray-200);
}
.prose > *:last-child,
.prose :is(.card, .q, .say, .ex, .trap, .proof, .note, details) > *:last-child {
  margin-bottom: 0;
}

/* Tables: hairlines, muted header; wide ones scroll inside .tw (and on phones by themselves). */
.prose table {
  width: 100%;
  margin: 0 0 var(--space-3);
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.5;
}
.prose th,
.prose td {
  padding: var(--space-2) var(--space-3) var(--space-2) 0;
  border-bottom: 1px solid var(--gray-200);
  text-align: left;
  vertical-align: top;
}
.prose th {
  font-weight: 600;
  color: var(--gray-500);
}
.prose tr:last-child > td {
  border-bottom: 0;
}
.prose .tw {
  margin: 0 0 var(--space-3);
  overflow-x: auto;
  scrollbar-width: thin;
}
.prose .tw > table {
  margin: 0;
}
/* Identifiers in tables never break mid-word: the table scrolls instead. */
.prose td code,
.prose th code {
  overflow-wrap: normal;
  word-break: normal;
}
@media (max-width: 639px) {
  .prose table:not(.tw > table) {
    display: block;
    overflow-x: auto;
  }
  /* Phones: a wide table bleeds to the edge of the screen (or card) and scrolls inside; cells keep a readable width. */
  .prose .tw {
    margin-inline: calc(-1 * var(--space-4));
    padding-inline: var(--space-4);
    scroll-padding-inline: var(--space-4);
  }
  .prose td,
  .prose th {
    min-width: 8em;
  }
  .prose td:first-child,
  .prose th:first-child {
    min-width: 4.5em;
  }
}
/* A fade on the side that has more (classes set by prep.js). */
.prose .tw.is-scrollable:not(.at-end) {
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent);
}
.prose .tw.is-scrollable.at-end:not(.at-start) {
  -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 32px), transparent);
  mask-image: linear-gradient(to left, #000 calc(100% - 32px), transparent);
}
.prose .tw.is-scrollable:not(.at-start):not(.at-end) {
  -webkit-mask-image: linear-gradient(to right, transparent, #000 32px, #000 calc(100% - 32px), transparent);
  mask-image: linear-gradient(to right, transparent, #000 32px, #000 calc(100% - 32px), transparent);
}

/* Math: display formulas scroll sideways instead of widening the page. */
.prose .katex {
  position: relative; /* keeps KaTeX's hidden MathML inside scrolling tables instead of widening the page */
  font-size: 1.05em;
}
.prose .katex-display {
  margin: var(--space-3) 0;
  padding: 2px 0;
  overflow-x: auto;
  overflow-y: hidden;
}

/* Cards */
.prose .card,
.prose .q {
  margin: var(--space-4) 0;
  padding: var(--space-4);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-card);
}
@media (min-width: 640px) {
  .prose .card,
  .prose .q {
    padding: var(--space-5) var(--space-6);
  }
}
/* The card a drill result or a link jumped to: a focus ring that fades out (prep.js adds .is-target). */
.prose .q.is-target {
  animation: target-ring 1400ms ease-out both;
}
@keyframes target-ring {
  0%,
  45% {
    box-shadow: 0 0 0 3px var(--focus), var(--shadow-card);
  }
  100% {
    box-shadow: 0 0 0 3px transparent, var(--shadow-card);
  }
}
.prose .q > h3:first-child,
.prose .card > h3:first-child {
  margin-top: 0;
}
.prose .q h3 .n {
  display: inline-flex;
  min-width: 40px;
  height: 24px;
  align-items: center;
  justify-content: center;
  margin-right: var(--space-2);
  padding: 0 var(--space-2);
  border-radius: var(--radius-full);
  background: var(--ink);
  color: var(--on-ink);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  vertical-align: 2px;
}
.prose .q:target {
  border-color: var(--gray-900);
}

/* Labelled notes: say aloud, example, trap, proof; labels come from CSS. */
.prose :is(.say, .ex, .trap) {
  margin: var(--space-3) 0;
  padding: var(--space-3) var(--space-4);
  border: 1px solid;
  border-radius: var(--radius-lg);
}
.prose :is(.say, .ex, .trap, .proof)::before {
  display: block;
  margin-bottom: var(--space-1);
  font-size: 11px;
  font-weight: 700;
  line-height: 16px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.prose .say {
  border-color: var(--brand-100);
  background: var(--brand-50);
}
.prose .say::before {
  content: 'Говоришь вслух';
  color: var(--brand-700);
}
.prose .ex {
  border-color: var(--green-200);
  background: var(--green-50);
}
.prose .ex::before {
  content: 'Пример';
  color: var(--green-700);
}
.prose .trap {
  border-color: var(--amber-200);
  background: var(--amber-50);
}
.prose .trap::before {
  content: 'Ловушка';
  color: var(--amber-700);
}
.prose .proof {
  margin: var(--space-3) 0;
  padding: var(--space-1) 0 var(--space-1) var(--space-4);
  border-left: 2px solid var(--gray-300);
}
.prose .proof::before {
  content: 'Доказательство';
  color: var(--gray-500);
}
.prose .note {
  margin: var(--space-3) 0;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  background: var(--gray-50);
  font-size: 15px;
}
.prose .q .note {
  /* inside a card: a toned block with a left bar, not a third bordered surface */
  border: 0;
  border-left: 3px solid var(--gray-300);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  background: var(--gray-50);
}
.prose .note--small,
.prose .foot {
  font-size: 13px;
  line-height: 1.6;
  color: var(--gray-500);
}

/* Muted line «Теория: …» under a heading */
.prose .th {
  margin: calc(-1 * var(--space-1)) 0 var(--space-3);
  font-size: 13px;
  line-height: 1.5;
  color: var(--gray-500);
}

/* Small pill label */
.prose .tag {
  display: inline-flex;
  height: 20px;
  align-items: center;
  margin: 0 var(--space-1);
  padding: 0 var(--space-2);
  border-radius: var(--radius-full);
  background: var(--brand-50);
  color: var(--brand-700);
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  vertical-align: 2px;
  white-space: nowrap;
}
.prose .tag:first-child {
  margin-left: 0;
}

/* Numbered steps with large numbers */
.prose ol.steps {
  counter-reset: step;
  padding-left: 0;
  list-style: none;
}
.prose ol.steps > li {
  position: relative;
  min-height: 32px;
  margin: 0 0 var(--space-3);
  padding-left: 44px;
  counter-increment: step;
}
.prose ol.steps > li::before {
  content: counter(step);
  position: absolute;
  top: 0;
  left: 0;
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: var(--radius-full);
  background: var(--ink);
  color: var(--on-ink);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
}

/* Two columns on desktop */
.prose .cols {
  display: grid;
  gap: var(--space-4);
  margin: var(--space-3) 0;
}
@media (min-width: 768px) {
  .prose .cols {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
.prose .cols > * {
  margin: 0;
}

/* Collapsible blocks */
.prose details {
  margin: var(--space-3) 0;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.prose details > summary {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-lg);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.prose details > summary::-webkit-details-marker {
  display: none;
}
.prose details > summary::before {
  content: '';
  width: 8px;
  height: 8px;
  flex: none;
  border-right: 2px solid var(--gray-500);
  border-bottom: 2px solid var(--gray-500);
  transform: rotate(-45deg);
  transition: transform var(--dur) ease;
}
.prose details[open] > summary::before {
  transform: rotate(45deg);
}
.prose details > summary:hover {
  background: var(--gray-50);
}
.prose details > :not(summary) {
  margin-inline: var(--space-4);
}
.prose details > :last-child {
  margin-bottom: var(--space-4);
}

/* «Скрыть ответы»: answers of .intro cards blur under a centred chip; a click (or Enter) shows one. */
.prose .intro .ans {
  position: relative;
  border-radius: var(--radius-md);
}
.prose .intro .ans > * {
  transition: filter 200ms ease;
}
.hide-answers .prose .intro .ans:not(.is-shown) {
  cursor: pointer;
  user-select: none;
}
.hide-answers .prose .intro .ans:not(.is-shown) > * {
  filter: blur(7px);
  pointer-events: none;
}
.hide-answers .prose .intro .ans:not(.is-shown)::after {
  content: 'Нажми, чтобы открыть';
  position: absolute;
  top: 50%;
  left: 50%;
  display: inline-flex;
  height: 28px;
  align-items: center;
  padding: 0 var(--space-3);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-full);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  color: var(--gray-700);
  white-space: nowrap;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.hide-answers .prose .intro .ans:not(.is-shown):hover::after {
  border-color: var(--gray-900);
  color: var(--gray-900);
}
.hide-answers .prose .intro .ans:not(.is-shown):focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

@media print {
  .prose .q {
    break-inside: avoid-page;
    box-shadow: none;
  }
  .hide-answers .prose .intro .ans {
    filter: none !important;
  }
}

/* Small «Вопрос по Л3» button at the top of a lecture's self-check (nested drill). */
.prose .drill-inline {
  margin: 0 0 var(--space-3);
}
.prose .drill-inline .btn {
  font-size: 13px;
}

/* Code blocks of prep pages: same highlighter as the code viewer, language label, copy button. */
.prose .code-block {
  margin: 0 0 var(--space-3);
  overflow: hidden;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  background: var(--gray-50);
}
.prose .code-block__bar {
  display: flex;
  min-height: 36px;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 0 var(--space-1) 0 var(--space-4);
  border-bottom: 1px solid var(--gray-200);
}
.prose .code-block__lang {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gray-500);
}
.prose .code-block__copy {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  gap: 6px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-full);
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-600);
  cursor: pointer;
}
@media (any-pointer: coarse) {
  .prose .code-block__copy {
    min-height: 44px;
  }
}
.prose .code-block__copy:hover {
  background: var(--gray-100);
  color: var(--gray-900);
}
.prose .code-block__copy .icon {
  width: 16px;
  height: 16px;
}
.prose .code-block .hl pre {
  margin: 0;
  padding: var(--space-3) var(--space-4);
  border: 0;
  border-radius: 0;
  background: transparent;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  tab-size: 4;
}
.prose .code-block .hl code {
  font-family: inherit;
  padding: 0;
  background: none;
  font-size: inherit;
  overflow-wrap: normal;
}

/* Pygments palette (classes of HtmlFormatter), shared by the code viewer and prep code blocks; both themes. */
.hl .c, .hl .c1, .hl .cm, .hl .cs, .hl .ch {
  color: var(--gray-500);
  font-style: italic;
}
.hl .cp, .hl .cpf {
  color: var(--amber-700);
}
.hl .k, .hl .kd, .hl .kn, .hl .kr, .hl .kc, .hl .kp, .hl .ow {
  color: var(--brand-600);
  font-weight: 600;
}
.hl .kt, .hl .nc, .hl .nn {
  color: var(--brand-700);
}
.hl .s, .hl .s1, .hl .s2, .hl .sb, .hl .sc, .hl .sd, .hl .sh, .hl .sx, .hl .sa, .hl .dl {
  color: var(--green-700);
}
.hl .se, .hl .si, .hl .sr, .hl .ss {
  color: var(--amber-700);
}
.hl .m, .hl .mi, .hl .mf, .hl .mh, .hl .mo, .hl .mb, .hl .il {
  color: var(--amber-700);
}
.hl .nf, .hl .fm {
  color: var(--gray-900);
  font-weight: 600;
}
.hl .nb, .hl .bp, .hl .nv, .hl .vi, .hl .vg {
  color: var(--brand-500);
}
.hl .na, .hl .nt, .hl .nd {
  color: var(--brand-600);
}
.hl .o {
  color: var(--gray-600);
}
.hl .err {
  color: var(--red-700);
}
.hl .gh, .hl .gu {
  color: var(--gray-900);
  font-weight: 700;
}
.hl .gd {
  color: var(--red-700);
}
.hl .gi {
  color: var(--green-700);
}
