/* ================================================================== */
/*  Mobile-safe math + tables + code (ported from fmin.xyz/optim)       */
/* ================================================================== */

/* KaTeX display blocks: scroll wide formulas instead of bleeding off-screen.
   Tiny vertical padding prevents top/bottom glyph crop (accents, surds). */
.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding-top: 1px;
  padding-bottom: 1px;
  -webkit-overflow-scrolling: touch;
}

/* \tag{} positioning: absolute (right-edge) on desktop, inline on phones —
   else the tag floats off-screen and gets clipped by the new overflow:auto. */
.katex-display > .katex > .katex-html > .tag {
  padding-left: 10px !important;
  margin-left: 10px !important;
  right: 0 !important;
}
@media (min-width: 613px) {
  .katex-display > .katex > .katex-html > .tag { position: absolute !important; }
}
@media (max-width: 612px) {
  .katex-display > .katex > .katex-html > .tag { position: static !important; }
}

/* MathML mirror that KaTeX emits is visually hidden but, in some Quarto
   builds, leaks intrinsic width and pushes the layout. Pin it to zero box. */
.katex-display .katex-mathml,
.katex .katex-mathml {
  position: absolute;
  clip: rect(1px, 1px, 1px, 1px);
  padding: 0;
  border: 0;
  height: 1px;
  width: 1px;
  overflow: hidden;
}

/* Tables: horizontal scroll instead of overflow. */
.table,
table {
  max-width: 100%;
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Code blocks: Quarto already sets overflow:auto, but pin width too. */
div.sourceCode,
pre,
pre.sourceCode {
  max-width: 100%;
  overflow-x: auto;
}

/* Long inline literals (URLs, identifiers) must wrap, not stretch the row. */
code, kbd, samp { overflow-wrap: anywhere; word-break: break-word; }

/* Mermaid / SVG figures should never be wider than their column. */
svg, .cell-output-display svg { max-width: 100%; height: auto; }

/* Page-level guard: clip any stray bleed at the body edge so phones don't
   get ghost horizontal scroll from MathJax/KaTeX paint artefacts. */
html, body { overflow-x: hidden; }

/* ================================================================== */
/*  EXISTING: callouts                                                  */
/* ================================================================== */
/* Tighten things up + book-feel */
.callout-historybox {
  border-left: 4px solid #a07050;
  background: #faf6ef;
  margin: 16px 0;
  padding: 10px 16px;
  border-radius: 4px;
}
.callout-historybox::before {
  content: "📜 Историческая справка";
  font-weight: 600;
  display: block;
  margin-bottom: 6px;
  color: #7a5030;
  font-family: ui-sans-serif, system-ui, sans-serif;
}
.callout-tasks {
  border-left: 4px solid #2e7d32;
  background: #f3faf3;
  margin: 16px 0;
  padding: 10px 16px;
  border-radius: 4px;
}
.callout-tasks::before {
  content: "✍️ Задачи";
  font-weight: 600;
  display: block;
  margin-bottom: 6px;
  color: #1e5021;
  font-family: ui-sans-serif, system-ui, sans-serif;
}
img { max-width: 100%; height: auto; }
figure img { display: block; margin: 0 auto; }
figure figcaption, .figure-caption { text-align: center; font-style: italic; color: #555; }

/* Index page hero */
.hero {
  background: linear-gradient(135deg, #f5f7fa 0%, #e6eef7 100%);
  border-radius: 12px;
  padding: 32px 28px;
  margin: 8px 0 28px 0;
  border: 1px solid #d9e2ec;
}
.hero h1 { margin-top: 0; font-size: 2.4em; }
.hero p { font-size: 1.08em; }
.hero .btn { margin-top: 8px; }
.hero-dop { background: linear-gradient(135deg, #fff7ed 0%, #fed7aa 100%); border-color: #fdba74; }
.hero-10  { background: linear-gradient(135deg, #eff6ff 0%, #bfdbfe 100%); border-color: #93c5fd; }
.hero-11  { background: linear-gradient(135deg, #ecfdf5 0%, #bbf7d0 100%); border-color: #6ee7b7; }

/* Status legend strip */
.legend {
  background: #fafafa;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 8px 14px;
  margin: 8px 0 16px 0;
  font-size: 0.92em;
}

/* Map tables — compact + zebra */
.grid table {
  margin: 0;
  font-size: 0.95em;
}
.grid table td:first-child {
  width: 32px;
  text-align: center;
  font-size: 1.15em;
  vertical-align: middle;
}
.grid table tbody tr:hover { background: #f5f9fd; }

/* Mermaid wider */
.cell-output-display .mermaid svg { max-width: 100% !important; height: auto; }

/* Book cards on landing -------------------------------- */
.book-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 18px;
  margin: 18px 0 32px 0;
}
.book-card {
  display: block;
  padding: 24px 22px;
  border-radius: 14px;
  border: 1px solid #e5e7eb;
  text-decoration: none !important;
  color: inherit;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  background: #fff;
}
.book-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 10px 30px rgba(0,0,0,0.10);
  text-decoration: none !important;
}
.book-card .book-icon { font-size: 2.6em; line-height: 1; margin-bottom: 8px; }
.book-card h3 { margin: 4px 0 6px 0; font-size: 1.35em; }
.book-card .book-tagline { color: #6b7280; font-size: 0.92em; margin: 0 0 14px 0; }
.book-card .book-toc { list-style: none; padding: 0; margin: 0 0 14px 0; }
.book-card .book-toc li {
  padding: 6px 0;
  border-bottom: 1px dashed #eef0f3;
  font-size: 0.9em;
}
.book-card .book-toc li:last-child { border-bottom: none; }
.book-card .book-toc em { color: #9ca3af; font-size: 0.86em; font-style: normal; }
.book-card .book-status {
  margin-top: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  background: #f7f8fa;
  font-size: 0.86em;
  color: #4b5563;
}
.book-dop { border-top: 4px solid #fb923c; }
.book-10  { border-top: 4px solid #60a5fa; }
.book-11  { border-top: 4px solid #34d399; }

/* Heatmap ---------------------------------------------- */
.hm-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0 18px 0;
  font-size: 0.82em;
}
.hm-pill {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(0,0,0,0.08);
  white-space: nowrap;
}
.hm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 6px;
  margin: 8px 0 22px 0;
}
.hm-sub {
  font-size: 0.7em;
  font-weight: 400;
  color: #888;
  margin-left: 8px;
}

/* Mega section titles */
.hm-section-title {
  margin-top: 32px;
  margin-bottom: 4px;
  font-size: 1.4em;
  border-bottom: 2px solid #e5e7eb;
  padding-bottom: 6px;
}
.hm-section-sub {
  font-size: 0.65em;
  font-weight: 400;
  color: #888;
}
.hm-section-meta {
  margin: 0 0 14px 0;
  color: #6b7280;
  font-size: 0.88em;
}

/* Chapter card */
.hm-chapter {
  margin: 10px 0 18px 0;
  padding: 8px 12px 12px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #fcfcfd;
}
.hm-chapter-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  text-decoration: none !important;
  margin-bottom: 8px;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.hm-chapter-head:hover { transform: translateX(2px); box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.hm-chapter-num { font-weight: 700; }
.hm-chapter-title { font-weight: 600; font-size: 1.05em; }
.hm-meta { margin-left: auto; font-size: 0.78em; opacity: 0.75; }

/* Sub-grid: smaller cells inside each chapter */
.hm-sub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 4px;
}
.hm-sub-cell {
  padding: 8px 8px;
  border-radius: 6px;
  font-size: 0.78em;
  line-height: 1.25;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  border: 1px solid rgba(0,0,0,0.05);
}
.hm-sub-cell.hm-0 { background: #ececec; color: #6b7280; }
.hm-sub-cell.hm-1 { background: #dbeafe; color: #1e3a8a; }
.hm-sub-cell.hm-2 { background: #fef3c7; color: #92400e; }
.hm-sub-cell.hm-3 { background: #fed7aa; color: #7c2d12; }
.hm-sub-cell.hm-4 { background: #bbf7d0; color: #064e3b; }
.hm-sub-cell.hm-5 { background: #4ade80; color: #052e16; font-weight: 600; }

/* Dark mode sub-cells */
.quarto-dark .hm-chapter { background: #1c1f24; border-color: #353a42; }
.quarto-dark .hm-sub-cell.hm-0 { background: #2a2e35; color: #8b95a5; }
.quarto-dark .hm-sub-cell.hm-1 { background: #1e3a8a; color: #c7d8ff; }
.quarto-dark .hm-sub-cell.hm-2 { background: #78350f; color: #ffe4a1; }
.quarto-dark .hm-sub-cell.hm-3 { background: #7c2d12; color: #ffd2b0; }
.quarto-dark .hm-sub-cell.hm-4 { background: #064e3b; color: #b6f4d4; }
.quarto-dark .hm-sub-cell.hm-5 { background: #15803d; color: #d3ffd9; }
.hm-cell {
  padding: 12px 10px;
  border-radius: 8px;
  font-size: 0.84em;
  line-height: 1.25;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  text-decoration: none !important;
  cursor: default;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  border: 1px solid rgba(0,0,0,0.06);
}
a.hm-cell { cursor: pointer; }
a.hm-cell:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.10); }

.hm-0 { background: #ececec; color: #6b7280; }
.hm-1 { background: #dbeafe; color: #1e3a8a; }
.hm-2 { background: #fef3c7; color: #92400e; }
.hm-3 { background: #fed7aa; color: #7c2d12; }
.hm-4 { background: #bbf7d0; color: #064e3b; }
.hm-5 { background: #4ade80; color: #052e16; font-weight: 600; }

/* Dark mode */
.quarto-dark .hm-0 { background: #2a2e35; color: #8b95a5; }
.quarto-dark .hm-1 { background: #1e3a8a; color: #c7d8ff; }
.quarto-dark .hm-2 { background: #78350f; color: #ffe4a1; }
.quarto-dark .hm-3 { background: #7c2d12; color: #ffd2b0; }
.quarto-dark .hm-4 { background: #064e3b; color: #b6f4d4; }
.quarto-dark .hm-5 { background: #15803d; color: #d3ffd9; }

/* ================================================================== */
/*  Landing — hero                                                    */
/* ================================================================== */

.sigma-hero {
  margin: 0.5rem 0 2.6rem;
  padding: 2.4rem 0 0.4rem;
  text-align: center;
}
.sigma-hero-sigma {
  font-family: "Palatino Linotype", Palatino, Georgia, serif;
  font-weight: 700;
  font-size: clamp(5rem, 17vw, 9rem);
  line-height: 0.9;
  color: #1a1a1a;
  background: linear-gradient(135deg, #7253ED 0%, #a00000 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.02em;
  display: block;
}
.quarto-dark .sigma-hero-sigma { filter: brightness(1.25); }
.sigma-hero-title {
  font-family: "et-book", Palatino, Georgia, serif;
  font-size: clamp(1.6rem, 4.5vw, 2.5rem);
  font-weight: 600;
  margin: 0.2rem 0 0.4rem;
  color: #1a1a1a;
}
.quarto-dark .sigma-hero-title { color: #f4f6f9; }
.sigma-hero-sub {
  font-size: clamp(1rem, 2.4vw, 1.2rem);
  line-height: 1.5;
  color: #5a5648;
  max-width: 46ch;
  margin: 0 auto;
}
.quarto-dark .sigma-hero-sub { color: #c5cbd4; }

/* Карточки-превью интерактивных сюжетов */
.sigma-hero-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin: 2.2rem 0 0.5rem;
  text-align: left;
}
.sigma-story-card {
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
  border: 1px solid rgba(0,0,0,0.10);
  text-decoration: none !important;
  color: inherit;
  transition: transform 0.1s ease, box-shadow 0.14s ease, border-color 0.14s;
}
.sigma-story-card:hover {
  transform: translateY(-3px);
  border-color: rgba(114,83,237,0.5);
  box-shadow: 0 10px 26px rgba(0,0,0,0.12);
}
.quarto-dark .sigma-story-card { background: #2a2f37; border-color: #404754; }
.quarto-dark .sigma-story-card:hover { border-color: #8b74f0; }
.sigma-story-card-img {
  aspect-ratio: 16 / 10;
  width: 100%;
  object-fit: cover;
  object-position: center;
  background: #f5f3e8;
  border-bottom: 1px solid rgba(0,0,0,0.06);
}
.quarto-dark .sigma-story-card-img { background: #1d2128; }
.sigma-story-card-body { padding: 0.7rem 0.85rem 0.85rem; }
.sigma-story-card-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #7253ED;
  margin-bottom: 0.25rem;
}
.quarto-dark .sigma-story-card-badge { color: #b8a8f0; }
.sigma-story-card-title {
  font-family: "et-book", Palatino, Georgia, serif;
  font-size: 1.02rem;
  font-weight: 600;
  line-height: 1.25;
  color: #1a1a1a;
  margin-bottom: 0.2rem;
}
.quarto-dark .sigma-story-card-title { color: #f4f6f9; }
.sigma-story-card-desc {
  font-size: 0.86rem;
  line-height: 1.4;
  color: #5a5648;
}
.quarto-dark .sigma-story-card-desc { color: #aab2bf; }

/* ================================================================== */
/*  Landing — PDF + assistant chips                                   */
/* ================================================================== */

.sigma-landing {
  margin: 2rem 0 2.5rem;
}

.sigma-pdf-btn {
  display: inline-block;
  padding: 0.75rem 1.4rem;
  font-size: 1.05rem;
  font-weight: 500;
  border-radius: 999px;
  background: #1a1a1a;
  color: #fff !important;
  text-decoration: none !important;
  border: 1px solid #1a1a1a;
  transition: transform 0.08s ease, box-shadow 0.12s ease;
}
.sigma-pdf-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.16);
}
.quarto-dark .sigma-pdf-btn {
  background: #fafafa;
  color: #111 !important;
  border-color: #fafafa;
}

.sigma-landing-assistant {
  margin-top: 2.25rem;
  padding: 1.25rem 1.4rem 1.4rem;
  border-radius: 14px;
  background: #f6f5f0;
  border: 1px solid rgba(0,0,0,0.06);
}
.quarto-dark .sigma-landing-assistant {
  background: #20242b;
  border-color: #333a44;
}

.sigma-landing-assistant-hint {
  font-size: 0.97rem;
  line-height: 1.45;
  color: #444;
  margin-bottom: 1rem;
}
.quarto-dark .sigma-landing-assistant-hint { color: #c5cbd4; }

.sigma-landing-chips {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.7rem;
}

.sigma-landing-chip {
  text-align: left;
  background: #fff;
  border: 1px solid rgba(0,0,0,0.10);
  border-radius: 12px;
  padding: 0.7rem 0.9rem;
  cursor: pointer;
  font: inherit;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  transition: transform 0.08s ease, box-shadow 0.12s ease, border-color 0.12s;
  color: inherit;
}
.sigma-landing-chip:hover {
  transform: translateY(-2px);
  border-color: rgba(0,0,0,0.25);
  box-shadow: 0 4px 14px rgba(0,0,0,0.08);
}
.sigma-landing-chip:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(0,0,0,0.10);
}
.quarto-dark .sigma-landing-chip {
  background: #2a2f37;
  border-color: #404754;
}
.quarto-dark .sigma-landing-chip:hover {
  border-color: #6a7382;
}

.sigma-landing-chip-kind {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #6b7280;
  font-weight: 500;
}
.quarto-dark .sigma-landing-chip-kind { color: #93a0b3; }

.sigma-landing-chip-text {
  font-size: 0.97rem;
  line-height: 1.35;
  color: #1a1a1a;
}
.quarto-dark .sigma-landing-chip-text { color: #f4f6f9; }
