/* Stage 1: reference reader. Isolated from the public article's layout. */
.btb-ref-panel[hidden], .btb-ref-backdrop[hidden] { display: none !important; }
.btb-ref-panel {
  position: fixed; z-index: 40; top: 0; right: 0; bottom: 0;
  display: flex; flex-direction: column; min-width: 0;
  width: var(--btb-ref-panel-width, 420px); max-width: 100vw;
  border-left: 1px solid var(--border); background: var(--surface); color: var(--text);
  box-shadow: -8px 0 26px rgba(0,0,0,.15);
}
.btb-ref-panel__grab { display: none; }
.btb-ref-panel__toolbar {
  display: flex; gap: 7px; align-items: center;
  padding: 10px 12px; border-bottom: 1px solid var(--border); flex: 0 0 auto;
}
.btb-ref-panel__toolbar button {
  min-width: 44px; min-height: 44px; padding: 8px 12px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--surface2); color: var(--text); cursor: pointer;
}
.btb-ref-panel__toolbar button:disabled { opacity: .35; cursor: default; }
/* «Закрити»: великий бурштиновий хрестик, щоб його було видно одразу (18.11.2026). */
.btb-ref-panel__toolbar [data-btb-ref-close] {
  padding: 0; font-size: 28px; line-height: 1; font-weight: 700; color: var(--accent); border-color: var(--accent);
}
.btb-ref-panel__toolbar [data-btb-ref-close]:hover { background: var(--accent-soft); }
.btb-ref-panel__full { margin-left: auto; font-size: 13px; overflow-wrap: anywhere; }
.btb-ref-panel__scroll { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 18px 20px; }
.btb-ref-panel__feedback { margin: 0; padding: 6px 20px; font-size: 14px; color: var(--muted); }
.btb-ref-panel__retry { min-height: 44px; margin: 12px 0; cursor: pointer; }
.btb-ref-document { min-width: 0; overflow-wrap: anywhere; }
.btb-ref-document h2 { margin: 0 0 16px; font-size: 23px; }
.btb-ref-document h3 { font-size: 19px; }
.btb-ref-document__body pre {
  max-width: 100%; overflow-x: auto; padding: 14px 16px; margin: 0;
  border: 1px solid var(--code-border); border-radius: 8px;
  background: var(--code-bg); color: var(--code-text);
  font: .86rem/1.55 var(--font-mono); white-space: pre;
}
.btb-ref-document__body pre code {
  display: inline; background: transparent; border: 0; padding: 0;
  color: inherit; font: inherit; white-space: inherit; overflow-wrap: normal;
}
.btb-ref-document table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; }
.btb-ref-document th, .btb-ref-document td { border: 1px solid var(--border); padding: 8px; }
.btb-ref-document .reference-output { margin: 14px 0; border-left: 3px solid var(--accent); padding: 10px 12px; background: var(--surface2); }
.btb-ref-document .reference-output pre { margin-top: 7px; }
.btb-ref-code { position: relative; margin: 15px 0; }
.btb-ref-code__actions { display: flex; gap: 8px; justify-content: flex-end; margin-bottom: 6px; }
.btb-ref-code__copy { min-height: 44px; padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px; color: var(--text); background: var(--surface2); cursor: pointer; }
/* Move only the lesson content, not the site header or footer, when width permits. */
.page-lesson.btb-ref-side .site-main > .container {
  max-width: none; margin-left: 0; margin-right: 0;
  width: calc(100% - var(--btb-ref-panel-width, 420px));
}
.page-lesson.btb-ref-side .lesson__main { min-width: 0; }
.btb-ref-backdrop { display: none; }
.page-lesson.btb-ref-sheet .btb-ref-backdrop {
  position: fixed; z-index: 38; inset: 0; display: block;
  background: rgba(0,0,0,.45);
}
.page-lesson.btb-ref-sheet .btb-ref-panel {
  top: auto; bottom: 0; left: 0; right: 0; width: 100%;
  height: var(--btb-ref-sheet-height, 60dvh); max-height: 100dvh;
  border-left: 0; border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.page-lesson.btb-ref-sheet .btb-ref-panel__grab {
  display: block; min-height: 44px; width: 100%; padding: 4px;
  border: 0; border-radius: 16px 16px 0 0; background: transparent; cursor: ns-resize;
  touch-action: pan-y;
}
.page-lesson.btb-ref-sheet .btb-ref-panel__grab::before {
  content: ''; display: block; margin: 12px auto; width: 48px; height: 5px;
  border-radius: 3px; background: var(--faint);
}
@media (prefers-reduced-motion: no-preference) {
  .page-lesson.btb-ref-sheet .btb-ref-panel { transition: height .15s ease; }
}
