@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,600;0,700;0,900;1,400;1,600&family=Source+Serif+4:ital,opsz,wght@0,8..60,300;0,8..60,400;0,8..60,600;1,8..60,300;1,8..60,400&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Tokens ───────────────────────────────────────────── */
:root {
  --black:          #111111;
  --ink-muted:    #3a3a3a;
  --ink-faint:    #767676;
  --paper:        #ffffff;
  --paper-warm:   #f5f5f3;
  --paper-code:   #f0f0ee;
  --rule:         #d8d8d4;
  --rule-strong:  #aaaaaa;
  --accent:       #c0392b;
  --accent-light: #e74c3c;
  --link:         #1a56a0;
  --link-hover:   #0d3a70;

  --font-display: 'Playfair Display', 'Georgia', serif;
  --font-body:    'Source Serif 4', 'Georgia', serif;
  --font-mono:    'JetBrains Mono', 'Courier New', monospace;

  --col-width:    680px;
  --side-pad:     clamp(1.25rem, 5vw, 3rem);
}

/* ── Page & Container ─────────────────────────────────── */
body {
  background-color: var(--paper);
  color: var(--black);
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.article {
  max-width: var(--col-width);
  margin: 0 auto;
  padding: 3.5rem var(--side-pad) 6rem;
}

/* ── Headings ─────────────────────────────────────────── */
.article h1,
.article h2,
.article h3,
.article h4,
.article h5,
.article h6 {
  font-family: var(--font-display);
  color: var(--black);
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin-top: 2.5em;
  margin-bottom: 0.6em;
}

/* H1 — Headline */
.article h1 {
  font-size: clamp(2rem, 5vw, 2.9rem);
  font-weight: 900;
  line-height: 1.1;
  margin-top: 0;
  padding-bottom: 1rem;
  border-bottom: 3px double var(--rule-strong);
}

/* H2 — Section title */
.article h2 {
  font-size: clamp(1.45rem, 3.5vw, 1.75rem);
  font-weight: 700;
  margin-top: 3em;
  padding-top: 0.75em;
  border-top: 1px solid var(--rule);
}

/* H3 — Sub-section */
.article h3 {
  font-size: 1.25rem;
  font-weight: 600;
  font-style: italic;
  color: var(--ink-muted);
}

/* H4 — Run-in head */
.article h4 {
  font-size: 1.05rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-style: normal;
  color: var(--ink-muted);
}

/* H5 */
.article h5 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink-faint);
}

/* H6 — Dateline / kicker */
.article h6 {
  font-size: 0.85rem;
  font-weight: 400;
  font-family: var(--font-body);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  margin-bottom: 0.3em;
}

/* ── Paragraphs ───────────────────────────────────────── */
.article p {
  margin: 0 0 1.5em;
  font-size: 1rem;
  font-weight: 300;
  hanging-punctuation: first;
}

/* Drop cap — first paragraph after H1 */
.article h1 + p::first-letter {
  float: left;
  font-family: var(--font-display);
  font-size: 4.2em;
  font-weight: 900;
  line-height: 0.82;
  margin: 0.06em 0.1em 0 0;
  color: var(--accent);
}

/* ── Emphasis & Inline ────────────────────────────────── */
.article strong,
.article b {
  font-weight: 600;
  color: var(--black);
}

.article em,
.article i {
  font-style: italic;
}

.article del,
.article s {
  text-decoration: line-through;
  color: var(--ink-faint);
}

.article mark {
  background: #f5e08a;
  color: var(--black);
  padding: 0 0.15em;
  border-radius: 2px;
}

.article sup,
.article sub {
  font-size: 0.7em;
  line-height: 0;
}

/* ── Links ────────────────────────────────────────────── */
.article a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color 0.15s;
}

.article a:hover {
  color: var(--link-hover);
  text-decoration-thickness: 2px;
}

/* ── Blockquote — Pull-quote style ───────────────────── */
.article blockquote {
  position: relative;
  margin: 2.5em 0;
  padding: 1.25em 1.75em 1.25em 2.25em;
  border-left: 4px solid var(--accent);
  background: var(--paper-warm);
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-style: italic;
  line-height: 1.5;
  color: var(--ink-muted);
}

.article blockquote::before {
  content: '\201C';
  position: absolute;
  top: -0.15em;
  left: 0.3em;
  font-size: 4rem;
  font-family: var(--font-display);
  font-weight: 900;
  color: var(--accent);
  line-height: 1;
  opacity: 0.25;
}

.article blockquote p {
  margin: 0;
  font-size: inherit;
}

/* Nested blockquote */
.article blockquote blockquote {
  font-size: 1rem;
  border-left-color: var(--rule-strong);
  margin: 1em 0;
}

/* ── Horizontal Rule ──────────────────────────────────── */
.article hr {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 3em 0;
}

/* ── Lists ────────────────────────────────────────────── */
.article ul,
.article ol {
  margin: 0 0 1.5em;
  padding-left: 1.6em;
}

.article li {
  margin-bottom: 0.45em;
  font-weight: 300;
}

.article ul {
  list-style: none;
  padding-left: 1.4em;
}

.article ul > li {
  position: relative;
}

.article ul > li::before {
  content: '—';
  position: absolute;
  left: -1.4em;
  color: var(--accent);
  font-weight: 400;
}

.article ol {
  list-style: decimal;
}

.article ol > li::marker {
  color: var(--accent);
  font-family: var(--font-display);
  font-weight: 700;
}

/* Nested lists */
.article ul ul,
.article ol ol,
.article ul ol,
.article ol ul {
  margin: 0.4em 0 0.4em 0.5em;
}

/* Level 2 bullet: dot */
.article ul ul > li::before {
  content: '\00B7';
  font-size: 1.4em;
  line-height: 0.85;
  color: var(--rule-strong);
}

/* Level 3 bullet: circle */
.article ul ul ul > li::before {
  content: '\25CB';
  font-size: 0.7em;
  line-height: 1.7;
  color: var(--ink-faint);
}

/* Task list (GFM checkboxes) */
.article ul.contains-task-list {
  padding-left: 0.4em;
}

.article li.task-list-item {
  list-style: none;
  padding-left: 0.2em;
}

.article li.task-list-item::before {
  display: none;
}

.article input[type='checkbox'] {
  appearance: none;
  -webkit-appearance: none;
  display: inline-block;
  width: 1em;
  height: 1em;
  border: 1.5px solid var(--rule-strong);
  border-radius: 2px;
  vertical-align: -0.15em;
  margin-right: 0.5em;
  position: relative;
}

.article input[type='checkbox']:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.article input[type='checkbox']:checked::after {
  content: '';
  position: absolute;
  top: 0.1em;
  left: 0.2em;
  width: 0.35em;
  height: 0.6em;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(45deg);
}

/* ── Code — Inline ────────────────────────────────────── */
.article code {
  font-family: var(--font-mono);
  font-size: 0.82em;
  background: var(--paper-code);
  color: var(--accent-light);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 0.1em 0.4em;
  white-space: nowrap;
}

/* ── Code — Block ─────────────────────────────────────── */
.article pre {
  background: #1c1c1e;
  border-left: 4px solid var(--accent);
  border-radius: 2px;
  margin: 2em 0;
  padding: 1.4em 1.6em;
  overflow-x: auto;
  font-size: 0.83rem;
  line-height: 1.65;
}

.article pre code {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  color: #e8e8e2;
  font-size: 1em;
  white-space: pre;
}

/* Syntax highlight via marked + highlight.js if used */
.article pre .hljs-keyword    { color: #f0a070; }
.article pre .hljs-string     { color: #a8cc8c; }
.article pre .hljs-comment    { color: #6a7d6a; font-style: italic; }
.article pre .hljs-number     { color: #89c4f4; }
.article pre .hljs-function   { color: #f0c060; }
.article pre .hljs-title      { color: #e0b060; }

/* ── Keyboard key ─────────────────────────────────────── */
.article kbd {
  font-family: var(--font-mono);
  font-size: 0.78em;
  display: inline-block;
  padding: 0.1em 0.45em;
  background: var(--paper-warm);
  border: 1px solid var(--rule-strong);
  border-bottom-width: 2px;
  border-radius: 3px;
  color: var(--ink-muted);
  white-space: nowrap;
}

/* ── Tables ───────────────────────────────────────────── */
.article table {
  width: 100%;
  border-collapse: collapse;
  margin: 2em 0;
  font-size: 0.92rem;
  font-family: var(--font-body);
  overflow-x: auto;
  display: block;
}

.article thead {
  border-top: 2px solid var(--black);
  border-bottom: 1px solid var(--black);
}

.article th {
  padding: 0.6em 1em;
  text-align: left;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
  background: transparent;
}

.article td {
  padding: 0.65em 1em;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
  color: var(--ink-muted);
  font-weight: 300;
}

.article tbody tr:last-child td {
  border-bottom: 2px solid var(--black);
}

.article tbody tr:hover td {
  background: var(--paper-warm);
}

.article th:first-child,
.article td:first-child {
  padding-left: 0;
}

.article th:last-child,
.article td:last-child {
  padding-right: 0;
}

/* ── Images ───────────────────────────────────────────── */
.article img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 2em 0 0.5em;
  border: 1px solid var(--rule);
}

/* Image caption via alt text rendered as figcaption
   (use wrapped <figure> if your renderer supports it) */
.article figure {
  margin: 2em 0;
  padding: 0;
}

.article figcaption {
  font-size: 0.83rem;
  color: var(--ink-faint);
  font-style: italic;
  text-align: center;
  margin-top: 0.5em;
  border-top: 1px solid var(--rule);
  padding-top: 0.4em;
}

/* ── Footnotes (GFM) ──────────────────────────────────── */
.article .footnotes {
  margin-top: 3em;
  padding-top: 1.25em;
  border-top: 1px solid var(--rule);
  font-size: 0.85rem;
  color: var(--ink-faint);
}

.article .footnotes ol {
  padding-left: 1.4em;
}

.article .footnotes li p {
  margin: 0;
}

.article a[href^="#fn"],
.article a[href^="#fnref"] {
  color: var(--accent);
  font-size: 0.75em;
  vertical-align: super;
  text-decoration: none;
  font-weight: 600;
}

/* ── Definition Lists (if renderer produces them) ─────── */
.article dl {
  margin: 1.5em 0;
}

.article dt {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--black);
  margin-top: 1em;
}

.article dd {
  margin-left: 1.5em;
  color: var(--ink-muted);
  font-weight: 300;
}

/* ── Abbreviation tooltip ─────────────────────────────── */
.article abbr[title] {
  text-decoration: underline dotted var(--rule-strong);
  cursor: help;
}

/* ── Small / Detail text ──────────────────────────────── */
.article small {
  font-size: 0.82em;
  color: var(--ink-faint);
}

/* ── Metadata byline block (optional .byline wrapper) ──── */
.article .byline {
  display: flex;
  align-items: center;
  gap: 0.75em;
  font-size: 0.85rem;
  color: var(--ink-muted);
  margin: 0.75em 0 2em;
  padding-bottom: 1.25em;
  border-bottom: 1px solid var(--rule);
}

.article .byline strong {
  color: var(--black);
  font-family: var(--font-display);
  font-weight: 600;
}

.article .byline time {
  font-style: italic;
}

/* ── Pull quote utility (.pullquote) ─────────────────── */
.article .pullquote {
  float: right;
  width: 42%;
  margin: 0.5em 0 1em 2em;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-style: italic;
  font-weight: 600;
  line-height: 1.35;
  color: var(--accent);
  border-top: 3px solid var(--accent);
  border-bottom: 1px solid var(--rule);
  padding: 0.7em 0;
}

/* ── Scrollbar ────────────────────────────────────────── */
.article pre::-webkit-scrollbar {
  height: 6px;
}

.article pre::-webkit-scrollbar-track {
  background: #2a2a2c;
}

.article pre::-webkit-scrollbar-thumb {
  background: #3d3d40;
  border-radius: 3px;
}

/* ── Video ────────────────────────────────────────────── */

/* Native <video> tag */
.article video {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  margin: 2em 0 0.5em;
  border: 1px solid var(--rule);
  background: #0d0c09;
}

/* Custom controls bar sits just below the video */
.article video + .video-caption,
.article .video-wrap + .video-caption {
  font-size: 0.83rem;
  color: var(--ink-faint);
  font-style: italic;
  border-top: 1px solid var(--rule);
  padding-top: 0.45em;
  margin-bottom: 2em;
}

/* ── Video wrapper — preserves aspect ratio ──────────── */
/* Surround <iframe> or <video> with <div class="video-wrap"> */
.article .video-wrap {
  position: relative;
  width: 100%;
  padding-top: 56.25%; /* 16:9 default */
  margin: 2em 0 0;
  border: 1px solid var(--rule);
  background: #0d0c09;
  overflow: hidden;
}

/* 4:3 variant */
.article .video-wrap.ratio-4-3  { padding-top: 75%; }
/* 1:1 variant */
.article .video-wrap.ratio-1-1  { padding-top: 100%; }
/* 21:9 cinematic */
.article .video-wrap.ratio-21-9 { padding-top: 42.86%; }

.article .video-wrap iframe,
.article .video-wrap video,
.article .video-wrap embed,
.article .video-wrap object {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
}

/* ── YouTube / Vimeo embed shorthand ─────────────────── */
/* marked.js renders bare links to video as <p><a>…</a></p>
   JS snippet below converts them; style the result here.   */
.article .embed-video {
  position: relative;
  width: 100%;
  padding-top: 56.25%;
  margin: 2em 0;
  border: 1px solid var(--rule);
  overflow: hidden;
  background: #0d0c09;
}

.article .embed-video iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
}

/* ── Video thumbnail placeholder (while loading) ─────── */
.article .video-thumb {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  margin: 2em 0;
  border: 1px solid var(--rule);
  overflow: hidden;
  cursor: pointer;
}

.article .video-thumb img {
  margin: 0;
  border: none;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: filter 0.2s;
}

.article .video-thumb:hover img {
  filter: brightness(0.85);
}

/* Play button overlay */
.article .video-thumb::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 4rem;
  height: 4rem;
  border-radius: 50%;
  background: rgba(139, 46, 13, 0.88);
  /* triangle via clip-path */
  clip-path: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M8 5v14l11-7z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 55%;
  transition: background-color 0.2s, transform 0.15s;
}

.article .video-thumb:hover::after {
  background-color: rgba(201, 68, 26, 0.95);
  transform: scale(1.08);
}

/* ── Inserted text <ins> ─────────────────────────────── */
.article ins {
  text-decoration: underline;
  text-decoration-style: solid;
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
  text-decoration-color: var(--accent);
  color: var(--black);
  font-style: normal;
}

/* ── Deeply nested blockquotes (3rd level) ───────────── */
.article blockquote blockquote blockquote {
  font-size: 0.9rem;
  border-left-color: var(--rule);
  background: transparent;
  font-style: normal;
  color: var(--ink-faint);
  padding: 0.5em 0.75em 0.5em 1.25em;
  margin: 0.75em 0;
}

.article blockquote blockquote blockquote::before {
  display: none;
}

/* ── Custom containers (markdown-it-container) ───────── */
/* ::: warning / ::: info / ::: danger / ::: tip / ::: note */

.article .custom-container {
  margin: 2em 0;
  padding: 1em 1.25em 1em 1.5em;
  border-left: 4px solid var(--rule-strong);
  background: var(--paper-warm);
  border-radius: 0 3px 3px 0;
  font-size: 0.95rem;
}

.article .custom-container p {
  margin: 0.3em 0;
}

.article .custom-container .custom-container-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.5em;
}

/* warning */
.article .custom-container.warning {
  border-left-color: #d97706;
  background: #fffbeb;
}

.article .custom-container.warning .custom-container-title {
  color: #92400e;
}

/* danger / error */
.article .custom-container.danger,
.article .custom-container.error {
  border-left-color: var(--accent);
  background: #fff5f5;
}

.article .custom-container.danger .custom-container-title,
.article .custom-container.error .custom-container-title {
  color: #991b1b;
}

/* info */
.article .custom-container.info {
  border-left-color: #2563eb;
  background: #eff6ff;
}

.article .custom-container.info .custom-container-title {
  color: #1e40af;
}

/* tip / success */
.article .custom-container.tip,
.article .custom-container.success {
  border-left-color: #16a34a;
  background: #f0fdf4;
}

.article .custom-container.tip .custom-container-title,
.article .custom-container.success .custom-container-title {
  color: #14532d;
}

/* note */
.article .custom-container.note {
  border-left-color: var(--rule-strong);
  background: var(--paper-warm);
}

.article .custom-container.note .custom-container-title {
  color: var(--ink-muted);
}

/* ── Details / Summary (collapsible blocks) ──────────── */
.article details {
  margin: 1.5em 0;
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 0.75em 1.25em;
  background: var(--paper-warm);
}

.article details[open] {
  padding-bottom: 1em;
}

.article summary {
  font-family: var(--font-display);
  font-weight: 600;
  cursor: pointer;
  color: var(--black);
  font-size: 0.95rem;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5em;
  user-select: none;
}

.article summary::-webkit-details-marker { display: none; }

.article summary::before {
  content: '▶';
  font-size: 0.6em;
  color: var(--accent);
  transition: transform 0.2s;
  display: inline-block;
}

.article details[open] > summary::before {
  transform: rotate(90deg);
}

.article details > *:not(summary) {
  margin-top: 0.75em;
}

/* ── Print ────────────────────────────────────────────── */
@media print {
  .article {
    max-width: 100%;
    padding: 0;
    font-size: 12pt;
  }

  .article h1 { font-size: 24pt; }
  .article h2 { font-size: 18pt; }

  .article a {
    color: var(--black);
    text-decoration: none;
  }

  .article a[href^='http']::after {
    content: ' (' attr(href) ')';
    font-size: 0.8em;
    color: var(--ink-faint);
  }

  .article pre,
  .article blockquote {
    page-break-inside: avoid;
  }

  .article h1,
  .article h2,
  .article h3 {
    page-break-after: avoid;
  }

  /* Replace embedded video with a placeholder label */
  .article .video-wrap,
  .article .embed-video,
  .article .video-thumb,
  .article video {
    display: block;
    background: var(--paper-warm);
    border: 1px solid var(--rule);
    padding: 1em;
    page-break-inside: avoid;
  }

  .article .video-wrap::before,
  .article .embed-video::before {
    content: '[Видео — недоступно при печати]';
    font-style: italic;
    color: var(--ink-faint);
    font-size: 0.85em;
  }

  .article .video-wrap iframe,
  .article .embed-video iframe {
    display: none;
  }
}

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 600px) {
  .article {
    font-size: 16px;
  }

  .article h1 {
    font-size: 1.8rem;
  }

  .article blockquote {
    font-size: 1.05rem;
    padding-left: 1.2em;
  }

  .article .pullquote {
    float: none;
    width: auto;
    margin: 1.5em 0;
  }

  .article table {
    font-size: 0.82rem;
  }
}