/* ============================================================
   GLAZNEV · Высшая математика · Современная дизайн-система
   © 2006—2026 В.А. Глазнев
   ============================================================ */

:root {
  --bg: #fafafa;
  --bg-soft: #f1f5f9;
  --bg-card: #ffffff;
  --fg: #0f172a;
  --fg-muted: #475569;
  --fg-soft: #64748b;
  --border: #e2e8f0;
  --border-soft: #f1f5f9;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #dbeafe;
  --success: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 20px;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-serif: "STIX Two Text", "Cambria Math", Cambria, Georgia, serif;
  --font-mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg: #0b1120;
  --bg-soft: #1e293b;
  --bg-card: #111827;
  --fg: #f1f5f9;
  --fg-muted: #cbd5e1;
  --fg-soft: #94a3b8;
  --border: #1e293b;
  --border-soft: #0f172a;
  --accent: #93c5fd;            /* ярче для контраста на тёмном */
  --accent-hover: #bfdbfe;
  --accent-soft: rgba(96, 165, 250, 0.18); /* лёгкий синий тинт, не тёмный */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============================================================
   ШАПКА
   ============================================================ */
.g-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
}

[data-theme="dark"] .g-header {
  background: rgba(11, 17, 32, 0.85);
}

.g-header__inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.g-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--fg);
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
}

.g-logo__mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent) 0%, #7c3aed 100%);
  color: #fff;
  border-radius: 10px;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: -0.5px;
}

.g-crumbs {
  flex: 1;
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 14px;
  color: var(--fg-soft);
  min-width: 0;
  overflow: hidden;
  flex-wrap: nowrap;
}

.g-crumbs a,
.g-crumbs span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 1;
  min-width: 0;
}

.g-crumbs a {
  color: var(--fg-soft);
  text-decoration: none;
  transition: color 0.15s var(--ease);
}

.g-crumbs a:hover { color: var(--accent); }

.g-crumbs__sep {
  opacity: 0.4;
  display: inline-flex;
  flex-shrink: 0;
  color: var(--fg-soft);
}

.g-crumbs__sep svg { width: 10px; height: 10px; }

.g-crumbs__current {
  color: var(--fg);
  font-weight: 500;
}

.g-header__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ============================================================
   КНОПКИ
   ============================================================ */
.g-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s var(--ease);
  white-space: nowrap;
  line-height: 1.3;
}

.g-btn--primary {
  background: var(--accent);
  color: #fff;
}

.g-btn--primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.g-btn--ghost {
  background: transparent;
  color: var(--fg-muted);
  border-color: var(--border);
}

.g-btn--ghost:hover {
  background: var(--bg-soft);
  color: var(--fg);
}

.g-btn--icon {
  padding: 8px;
  width: 36px;
  height: 36px;
  justify-content: center;
}

/* ============================================================
   СЕТКА СТРАНИЦЫ
   ============================================================ */
.g-page {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.g-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  width: 100%;
}

.g-container--narrow {
  max-width: 860px;
}

.g-container--wide {
  max-width: 1400px;
}

/* ============================================================
   HERO
   ============================================================ */
.g-hero {
  padding: 80px 0 56px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.g-hero::before {
  content: "";
  position: absolute;
  top: -200px;
  left: 50%;
  transform: translateX(-50%);
  width: 900px;
  height: 500px;
  background: radial-gradient(closest-side, rgba(37, 99, 235, 0.08), transparent);
  pointer-events: none;
  z-index: 0;
}

.g-hero > * { position: relative; z-index: 1; }

.g-hero__eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 20px;
  letter-spacing: 0.02em;
}

.g-hero__title {
  font-size: clamp(32px, 5vw, 52px);
  font-weight: 800;
  line-height: 1.1;
  margin: 0 0 16px;
  letter-spacing: -0.03em;
  color: var(--fg);
}

.g-hero__title em {
  background: linear-gradient(135deg, var(--accent) 0%, #7c3aed 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-style: normal;
}

.g-hero__subtitle {
  font-size: clamp(16px, 2vw, 19px);
  color: var(--fg-muted);
  max-width: 680px;
  margin: 0 auto 32px;
  line-height: 1.5;
}

.g-hero__actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* SVG-иконка-стрелка (для ссылок «читать / открыть / назад») */
.g-icon-arrow {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  vertical-align: middle;
  display: inline-block;
  margin-left: 6px;
}

.g-icon-arrow + *:not(.g-icon-arrow),
*:not(.g-icon-arrow) + .g-icon-arrow {
  /* keep spacing consistent when adjacent to text */
}

.g-card__arrow .g-icon-arrow,
.g-btn .g-icon-arrow {
  margin-left: 4px;
}

/* Стрелка «назад» (первая в кнопке) — отступ справа вместо слева */
.g-btn > .g-icon-arrow:first-child {
  margin-left: 0;
  margin-right: 4px;
}

.g-pager__btn > .g-icon-arrow:first-child {
  margin-right: 6px;
  margin-left: 0;
}

/* ============================================================
   КАРТОЧКИ
   ============================================================ */
.g-section {
  padding: 40px 0 64px;
}

.g-section__title {
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 8px;
  letter-spacing: -0.02em;
}

.g-section__lead {
  color: var(--fg-muted);
  margin: 0 0 28px;
  font-size: 15px;
}

.g-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.g-grid--2 { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }

.g-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 22px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--fg);
  transition: all 0.2s var(--ease);
  position: relative;
  overflow: hidden;
}

.g-card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 1px solid transparent;
  pointer-events: none;
  transition: border-color 0.2s var(--ease);
}

.g-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: transparent;
}

.g-card:hover::after { border-color: var(--accent); }

.g-card__icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 22px;
  margin-bottom: 4px;
}

.g-card__title {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.g-card__desc {
  font-size: 14px;
  color: var(--fg-muted);
  margin: 0;
  line-height: 1.5;
}

.g-card__meta {
  margin-top: auto;
  padding-top: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--fg-soft);
}

.g-card__arrow {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--accent);
  font-weight: 500;
  transition: gap 0.15s var(--ease);
}

.g-card:hover .g-card__arrow { gap: 8px; }

.g-tag {
  display: inline-block;
  padding: 2px 8px;
  background: var(--bg-soft);
  color: var(--fg-muted);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
}

/* ============================================================
   СПИСОК ГЛАВ (оглавление)
   ============================================================ */
.g-toc {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.g-toc__item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--fg);
  transition: background 0.15s var(--ease);
  font-size: 15px;
}

.g-toc__item:hover {
  background: var(--bg-soft);
}

.g-toc__num {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.g-toc__text { flex: 1; }

.g-toc__arrow {
  color: var(--fg-soft);
  transition: transform 0.15s var(--ease);
}

.g-toc__item:hover .g-toc__arrow {
  transform: translateX(3px);
  color: var(--accent);
}

/* ============================================================
   КОНТЕНТ ЛЕКЦИЙ
   ============================================================ */
.g-content {
  max-width: 860px;
  margin: 0 auto;
  padding: 40px 24px 80px;
  font-size: 17px;
  line-height: 1.7;
  color: var(--fg);
  overflow-wrap: break-word;
  word-wrap: break-word;
}

.g-content h1,
.g-content h2,
.g-content h3,
.g-content h4 {
  color: var(--fg);
  letter-spacing: -0.02em;
  line-height: 1.25;
  margin: 2em 0 0.6em;
}

.g-content h1 { font-size: 34px; font-weight: 800; margin-top: 0; }
.g-content h2 { font-size: 26px; font-weight: 700; }
.g-content h3 { font-size: 21px; font-weight: 600; }
.g-content h4 { font-size: 18px; font-weight: 600; }

.g-content p {
  margin: 0 0 1em;
}

.g-content img {
  max-width: 100%;
  height: auto;
  vertical-align: middle;
  display: inline-block;
}

.g-content table {
  margin: 1.2em auto;
  border-collapse: collapse;
  max-width: 100%;
}

.g-content table img { display: block; max-width: none; }

.g-content a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s var(--ease);
}

.g-content a:hover {
  border-bottom-color: var(--accent);
}

.g-content center {
  display: block;
  text-align: center;
  margin: 1em 0;
}

.g-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2em 0;
}

.g-content ul,
.g-content ol {
  padding-left: 24px;
  margin: 0 0 1em;
}

.g-content li { margin: 0.3em 0; }

.g-content b, .g-content strong { font-weight: 600; }

.g-content blockquote {
  margin: 1.2em 0;
  padding: 12px 20px;
  background: var(--bg-soft);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--fg-muted);
}

.g-content pre,
.g-content code {
  font-family: var(--font-mono);
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  font-size: 0.92em;
}

.g-content pre {
  padding: 16px;
  overflow-x: auto;
}

/* ============================================================
   НИЖНЯЯ НАВИГАЦИЯ (prev/next)
   ============================================================ */
.g-pager {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  padding: 24px 0 0;
  margin-top: 40px;
  border-top: 1px solid var(--border);
}

.g-pager__btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  text-decoration: none;
  font-size: 14px;
  transition: all 0.15s var(--ease);
  max-width: 280px;
}

.g-pager__btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}

.g-pager__btn--prev { justify-self: start; text-align: left; }
.g-pager__btn--next { justify-self: end; text-align: right; }
.g-pager__btn--center { justify-self: center; }

.g-pager--auto {
  margin-top: 56px;
}

.g-pager__btn--next > span { display: inline-flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.g-pager__btn--prev > span { display: inline-flex; flex-direction: column; align-items: flex-start; gap: 2px; }

.g-pager__hint {
  font-size: 11px;
  color: var(--fg-soft);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 2px;
  display: block;
}

.g-pager__label {
  font-weight: 500;
  display: block;
}

/* ============================================================
   ПОДВАЛ
   ============================================================ */
.g-footer {
  margin-top: auto;
  padding: 32px 0;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--fg-soft);
  font-size: 14px;
}

.g-footer__inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.g-footer a {
  color: var(--fg-muted);
  text-decoration: none;
}

.g-footer a:hover { color: var(--accent); }

/* ============================================================
   КНОПКА «НАВЕРХ»
   ============================================================ */
.g-fab-top {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 90;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--fg);
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: all 0.2s var(--ease);
}

.g-fab-top--visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.g-fab-top:hover {
  color: var(--accent);
  border-color: var(--accent);
  transform: translateY(-2px);
}

/* ============================================================
   ПОСЕЩЁННЫЕ ССЫЛКИ (прогресс)
   ============================================================ */
.g-content a.g-visited::before,
.g-toc a.g-visited::before,
.g-toc__item.g-visited::before {
  content: "✓";
  color: var(--success);
  margin-right: 6px;
  font-weight: 700;
  display: inline-block;
}

/* ============================================================
   ПОИСК
   ============================================================ */
.g-search {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 80px 16px 16px;
}

.g-search__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: g-fade-in 0.15s var(--ease);
}

.g-search__panel {
  position: relative;
  width: 100%;
  max-width: 640px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: g-pop 0.2s var(--ease);
}

.g-search__input-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.g-search__icon {
  color: var(--fg-soft);
  flex-shrink: 0;
}

.g-search__input {
  flex: 1;
  font: inherit;
  font-size: 17px;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--fg);
  min-width: 0;
}

.g-search__input::placeholder { color: var(--fg-soft); }

.g-search__kbd {
  font: inherit;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--bg-soft);
  color: var(--fg-soft);
  border: 1px solid var(--border);
  cursor: pointer;
}

.g-search__results {
  max-height: 60vh;
  overflow-y: auto;
  padding: 8px;
}

.g-search__hit {
  display: block;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--fg);
}

.g-search__hit.is-active {
  background: var(--accent-soft);
  color: var(--fg);
}

.g-search__hit-title {
  font-size: 15px;
  font-weight: 500;
  line-height: 1.3;
}

.g-search__hit-meta {
  font-size: 12px;
  color: var(--fg-soft);
  margin-top: 2px;
}

.g-search__empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--fg-soft);
  font-size: 14px;
}

.g-search__hint {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--fg-soft);
  text-align: center;
}

@keyframes g-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes g-pop { from { opacity: 0; transform: translateY(-10px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ============================================================
   АДАПТИВ
   ============================================================ */
@media (max-width: 900px) {
  .g-header__inner { flex-wrap: wrap; gap: 10px; }
  .g-crumbs { order: 3; width: 100%; flex-basis: 100%; }
  .g-header__actions { margin-left: auto; }
}

@media (max-width: 768px) {
  .g-hero { padding: 48px 0 32px; }
  .g-section { padding: 24px 0 48px; }
  .g-container { padding: 0 16px; }
  .g-content { padding: 24px 16px 60px; font-size: 16px; }
  .g-pager { grid-template-columns: 1fr; }
  .g-pager__btn--prev,
  .g-pager__btn--next,
  .g-pager__btn--center { justify-self: stretch; max-width: none; }
  .g-header__inner { padding: 12px 16px; gap: 8px; }
  .g-logo { font-size: 14px; }
  .g-logo__mark { width: 30px; height: 30px; font-size: 12px; }
  .g-btn { font-size: 13px; padding: 8px 12px; }
  .g-btn--icon { width: 34px; height: 34px; padding: 6px; }
}

@media (max-width: 480px) {
  .g-logo span:not(.g-logo__mark) { display: none; }
  .g-hero { padding: 32px 0 24px; }
  .g-hero__title { font-size: 28px; }
  .g-hero__subtitle { font-size: 15px; }
  .g-card { padding: 18px; }
  .g-grid { grid-template-columns: 1fr; gap: 12px; }
}

/* ============================================================
   УТИЛИТЫ
   ============================================================ */
.g-hide-sm { }
@media (max-width: 640px) { .g-hide-sm { display: none; } }

.g-muted { color: var(--fg-soft); }
.g-center { text-align: center; }

.g-divider {
  height: 1px;
  background: var(--border);
  margin: 32px 0;
  border: none;
}

/* Плавное появление */
@media (prefers-reduced-motion: no-preference) {
  .g-card, .g-toc__item {
    animation: g-fade 0.4s var(--ease) backwards;
  }
  .g-card:nth-child(2), .g-toc__item:nth-child(2) { animation-delay: 0.05s; }
  .g-card:nth-child(3), .g-toc__item:nth-child(3) { animation-delay: 0.1s; }
  .g-card:nth-child(4), .g-toc__item:nth-child(4) { animation-delay: 0.15s; }
  .g-card:nth-child(5), .g-toc__item:nth-child(5) { animation-delay: 0.2s; }
  .g-card:nth-child(n+6), .g-toc__item:nth-child(n+6) { animation-delay: 0.25s; }
}

@keyframes g-fade {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   ОГЛАВЛЕНИЕ cdp_mat (статический fallback DHTML-меню)
   ============================================================ */
.g-cdp-toc {
  list-style: none;
  margin: 0 0 24px;
  padding: 0;
}
.g-cdp-toc ul {
  list-style: none;
  padding-left: 18px;
  margin: 4px 0 12px;
  border-left: 2px solid var(--border);
}
.g-cdp-toc li {
  margin: 4px 0;
  padding-left: 12px;
  position: relative;
}
.g-cdp-toc a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 120ms var(--ease);
}
.g-cdp-toc a:hover { border-bottom-color: var(--accent); }
.g-cdp-toc__heading {
  font-weight: 600;
  color: var(--fg);
  display: inline-block;
  margin-top: 8px;
}
.g-cdp-toc > li > .g-cdp-toc__heading {
  font-size: 17px;
  margin-top: 18px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  display: block;
}

/* ============================================================
   ДОПОЛНИТЕЛЬНЫЕ УЛУЧШЕНИЯ UI/UX
   ============================================================ */

/* ── A11Y: focus-visible для клавиатуры ─────────────────────── */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
.g-btn:focus-visible,
.g-card:focus-visible,
.g-pager__btn:focus-visible {
  outline-offset: 3px;
}

/* ── Skip link для скринридеров ──────────────────────────────── */
.g-skip {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  z-index: 999;
  border-radius: 0 0 8px 0;
  font-weight: 600;
  text-decoration: none;
}
.g-skip:focus { left: 0; }

/* ── Таблицы 2006 года: горизонтальная прокрутка на мобиле ──── */
@media (max-width: 768px) {
  .g-content table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    margin-left: -16px;
    margin-right: -16px;
    padding: 0 16px;
    /* возвращаем семантику строк */
  }
  .g-content table > tbody { display: table; min-width: 100%; }
}

/* ── Длинные слова / ссылки не должны ломать вёрстку ─────────── */
.g-content a,
.g-content code,
.g-content pre {
  overflow-wrap: anywhere;
}

/* ── safe-area для iPhone с notch ─────────────────────────────── */
@supports (padding: env(safe-area-inset-bottom)) {
  .g-footer__inner {
    padding-bottom: env(safe-area-inset-bottom);
  }
  .g-fab-top {
    bottom: max(24px, env(safe-area-inset-bottom));
    right: max(16px, env(safe-area-inset-right));
  }
  .g-header__inner {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
}

/* ── Тап-таргеты ≥ 44×44px на тач-устройствах ─────────────────── */
@media (hover: none) and (pointer: coarse) {
  .g-btn { min-height: 44px; }
  .g-btn--icon { width: 44px; height: 44px; }
  .g-fab-top { width: 48px; height: 48px; }
  .g-pager__btn { min-height: 56px; padding: 14px 18px; }
  .g-toc__item { padding: 16px 18px; }
  .g-search__hit { padding: 14px; }
  .g-content a { padding: 2px 0; }
}

/* ── Tablet breakpoint (planshet) ─────────────────────────────── */
@media (max-width: 1024px) and (min-width: 769px) {
  .g-container { padding: 0 20px; }
  .g-hero { padding: 64px 0 40px; }
  .g-content { padding: 32px 22px 64px; font-size: 16.5px; }
}

/* ── Phone tightening (≤480px) ────────────────────────────────── */
@media (max-width: 480px) {
  .g-content {
    padding: 20px 14px 48px;
    font-size: 15.5px;
    line-height: 1.65;
  }
  .g-content h1 { font-size: 26px; }
  .g-content h2 { font-size: 21px; }
  .g-content h3 { font-size: 18px; }
  .g-hero__title { font-size: clamp(24px, 7vw, 32px); }
  .g-hero__subtitle { font-size: 14.5px; }
  .g-section__title { font-size: 20px; }
  .g-card { padding: 16px; gap: 8px; }
  .g-card__title { font-size: 17px; }
  .g-card__desc { font-size: 13.5px; }
  .g-pager { gap: 8px; padding-top: 16px; margin-top: 28px; }
  .g-pager__btn { padding: 12px 14px; font-size: 13.5px; }
  .g-pager__hint { font-size: 10px; }
  .g-footer { padding: 20px 0; font-size: 13px; }
  .g-footer__inner { flex-direction: column; gap: 6px; }
  .g-search { padding: 16px 8px; }
  .g-search__panel { max-height: calc(100vh - 32px); }
  .g-search__results { max-height: calc(100vh - 220px); }
  .g-search__input { font-size: 16px; /* iOS: ≥16px = no auto-zoom */ }
}

/* ── Очень узкие экраны (≤360px, старые андроиды) ──────────────── */
@media (max-width: 360px) {
  .g-header__actions .g-btn:not(.g-btn--icon) { padding: 8px 10px; }
  .g-hero { padding: 24px 0 16px; }
  .g-section { padding: 16px 0 32px; }
}

/* ── Большие экраны (≥1400px) — расширим читаемую область  ───── */
@media (min-width: 1400px) {
  .g-hero { padding: 96px 0 64px; }
  .g-content { font-size: 17.5px; }
}

/* ── Search-модалка: на телефонах почти-фуллскрин ─────────────── */
@media (max-width: 640px) {
  .g-search { padding: 8px; align-items: stretch; }
  .g-search__panel {
    max-width: none;
    width: 100%;
    border-radius: var(--radius);
    max-height: 100vh;
  }
  .g-search__results { max-height: calc(100vh - 200px); }
}

/* ── prefers-reduced-motion: убрать всю анимацию ──────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  html { scroll-behavior: auto; }
}

/* ── Автотема: уважаем системную тёмную, если пользователь не выбрал ── */
@media (prefers-color-scheme: dark) {
  html:not([data-theme]) {
    --bg: #0b1120;
    --bg-soft: #1e293b;
    --bg-card: #111827;
    --fg: #f1f5f9;
    --fg-muted: #cbd5e1;
    --fg-soft: #94a3b8;
    --border: #1e293b;
    --border-soft: #0f172a;
    --accent: #93c5fd;
    --accent-hover: #bfdbfe;
    --accent-soft: rgba(96, 165, 250, 0.18);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
  }
  html:not([data-theme]) .g-header { background: rgba(11, 17, 32, 0.85); }
}

/* ── Sticky-header при скролле: лёгкая тень ───────────────────── */
.g-header { transition: box-shadow 0.2s var(--ease); }
.g-header.is-scrolled { box-shadow: 0 1px 0 var(--border), 0 2px 8px rgba(15,23,42,0.04); }

/* ── Интерактивный focus-ring у тёмной темы — контрастный ──── */
[data-theme="dark"] :focus-visible { outline-color: #60a5fa; }

/* ── Solid-синие элементы (кнопка primary, лого) сохраняют насыщенный
      синий фон и в тёмной теме — иначе белый текст на бледно-голубом
      теряет читаемость. ──────────────────────────────────────────── */
[data-theme="dark"] .g-btn--primary,
html:not([data-theme]) .g-btn--primary {
  background: #2563eb;
  color: #fff;
}
[data-theme="dark"] .g-btn--primary:hover,
html:not([data-theme]) .g-btn--primary:hover {
  background: #1d4ed8;
}
[data-theme="dark"] .g-logo__mark {
  background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme]) .g-logo__mark {
    background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
  }
}

/* ── Selection (выделение текста) ─────────────────────────────── */
::selection {
  background: #2563eb;
  color: #fff;
}

/* ── Скроллбар (Webkit/Blink) — компактный ────────────────────── */
@media (hover: hover) {
  ::-webkit-scrollbar { width: 10px; height: 10px; }
  ::-webkit-scrollbar-track { background: var(--bg); }
  ::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 5px;
    border: 2px solid var(--bg);
  }
  ::-webkit-scrollbar-thumb:hover { background: var(--fg-soft); }
}

/* ── ПЕЧАТЬ ────────────────────────────────────────────────────
   Студенту нужно распечатать лекцию — убираем шапку, футер, пейджер,
   делаем чёрно-белый макет. */
@media print {
  @page { margin: 18mm 14mm; }
  body { background: #fff !important; color: #000 !important; font-size: 12pt; }
  .g-header, .g-footer, .g-fab-top, .g-pager, .g-search,
  [data-theme-toggle], [data-search-open], .g-toc__nav {
    display: none !important;
  }
  .g-content {
    max-width: none;
    padding: 0;
    font-size: 11pt;
    line-height: 1.5;
    color: #000;
    overflow-wrap: break-word;
  }
  .g-content a { color: #000; text-decoration: underline; }
  .g-content a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 0.85em;
    color: #555;
    word-break: break-all;
  }
  .g-content img { max-width: 100% !important; page-break-inside: avoid; }
  .g-content h1, .g-content h2, .g-content h3 { page-break-after: avoid; }
  .g-content table { page-break-inside: avoid; }
  /* картинки-формулы как inline */
  .g-content p img, .g-content li img { page-break-inside: avoid; }
}
