:root {
  --bg: #f7f5f2;
  --paper: #ffffff;
  --ink: #121212;
  --muted: #5c5c5c;
  --line: #e6e2dc;
  --accent: #d61f26;
  --accent-deep: #8f1218;
  --expert: #f0eeea;
  --stats: #f8e9ea;
  --code: #f3f0eb;
  --max: 52rem;
  --outline: 15.5rem;
  --edit-rail: 6.75rem;
  --shell: calc(var(--outline) + var(--max) + 2.5rem + var(--edit-rail));
  --wide: var(--shell);
  --font: "Manrope", "Segoe UI", sans-serif;
  --display: "Fraunces", Georgia, serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 480px at 10% -10%, rgba(214, 31, 38, 0.08), transparent 60%),
    radial-gradient(900px 420px at 100% 0%, rgba(18, 18, 18, 0.05), transparent 55%),
    var(--bg);
  line-height: 1.65;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

a:hover {
  color: var(--accent-deep);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar__inner {
  max-width: var(--wide);
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand__mark {
  width: 1.7rem;
  height: 1.7rem;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
}

.brand__name {
  font-size: 1.05rem;
}

.topnav {
  display: none;
  gap: 1rem;
  flex: 1;
}

.topnav a {
  color: var(--ink);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
}

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

.topbar__badge {
  margin-left: auto;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent-deep);
  background: var(--stats);
  padding: 0.35rem 0.65rem;
  white-space: nowrap;
}

.promo {
  background: #e8f2fb;
  color: #16324a;
  text-align: center;
  font-size: 0.92rem;
  font-weight: 500;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid #d5e6f4;
  animation: fade-down 0.55s ease both;
}

.page-shell {
  max-width: var(--shell);
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
  display: grid;
  gap: 1.5rem;
  align-items: start;
  overflow: visible;
}

.article {
  min-width: 0;
  max-width: var(--max);
  width: 100%;
  overflow: visible;
}

.outline {
  display: none;
}

.outline__title {
  margin: 0 0 0.75rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.outline__nav {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  border-left: 1px solid var(--line);
}

.outline__link {
  position: relative;
  display: block;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.84rem;
  line-height: 1.35;
  padding: 0.35rem 0.55rem 0.35rem 0.85rem;
  border-left: 2px solid transparent;
  margin-left: -1px;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.outline__link--h2 {
  font-weight: 650;
  color: #333;
}

.outline__link--h3 {
  font-weight: 500;
  padding-left: 1.45rem;
  font-size: 0.8rem;
}

.outline__link:hover {
  color: var(--accent-deep);
  background: rgba(214, 31, 38, 0.05);
}

.outline__link.is-active {
  color: var(--accent-deep);
  border-left-color: var(--accent);
  background: rgba(214, 31, 38, 0.07);
  font-weight: 700;
}

.crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 1.25rem;
}

.crumbs a {
  color: var(--muted);
  text-decoration: none;
}

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

.article__head {
  display: grid;
  gap: 1rem;
  margin-bottom: 1.5rem;
  animation: fade-up 0.6s ease both;
}

.article__titles h1 {
  margin: 0 0 0.75rem;
  font-family: var(--display);
  font-size: clamp(2rem, 4.5vw, 3.1rem);
  line-height: 1.12;
  letter-spacing: -0.02em;
  font-weight: 700;
}

.deck {
  margin: 0;
  font-size: 1.15rem;
  color: var(--muted);
  max-width: 40rem;
}

.article__meta {
  font-size: 0.88rem;
  color: var(--muted);
}

.expert {
  display: grid;
  gap: 1rem;
  background: var(--expert);
  border: 1px solid var(--line);
  padding: 1.1rem 1.15rem;
  margin-bottom: 1.5rem;
  animation: fade-up 0.7s ease 0.08s both;
}

.eyebrow {
  margin: 0 0 0.35rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.expert__name {
  margin: 0;
  font-weight: 700;
  font-size: 1.05rem;
}

.expert__role {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.expert__blurb {
  margin: 0;
  color: #333;
  font-size: 0.95rem;
}

.expert__stats {
  background: var(--stats);
  border: 1px solid #f0d0d2;
  padding: 0.85rem 1rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  text-align: center;
}

.stats strong {
  display: block;
  font-family: var(--display);
  font-size: 1.35rem;
  color: var(--accent-deep);
  line-height: 1.1;
}

.stats span {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.hero {
  position: relative;
  overflow: hidden;
  min-height: 14rem;
  margin: 0 0 1.75rem;
  padding: 2.4rem 1.5rem;
  color: #fff;
  background:
    linear-gradient(135deg, #7a0f16 0%, #d61f26 42%, #2a1214 100%);
  display: grid;
  align-content: end;
  gap: 0.35rem;
  animation: hero-in 0.8s ease both;
}

.hero__glow {
  position: absolute;
  inset: -20% 30% auto auto;
  width: 18rem;
  height: 18rem;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.22), transparent 65%);
  pointer-events: none;
}

.hero__eyebrow,
.hero__title,
.hero__sub {
  position: relative;
  margin: 0;
}

.hero__eyebrow {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.85;
}

.hero__title {
  font-family: var(--display);
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.hero__sub {
  font-size: 1.05rem;
  opacity: 0.92;
  max-width: 28rem;
}

.prose {
  --prose-pad-x: 1.25rem;
  background: var(--paper);
  border: 1px solid var(--line);
  padding: 1.5rem var(--prose-pad-x) 2rem;
  animation: fade-up 0.75s ease 0.12s both;
  overflow: visible;
}

.prose > :first-child {
  margin-top: 0;
}

.prose h1 {
  display: none;
}

.prose h2 {
  margin: 2.4rem 0 0.9rem;
  padding-top: 0.4rem;
  font-family: var(--display);
  font-size: 1.65rem;
  line-height: 1.2;
  letter-spacing: -0.015em;
  scroll-margin-top: 5.5rem;
}

.prose h3 {
  margin: 1.8rem 0 0.7rem;
  font-size: 1.15rem;
  font-weight: 700;
  scroll-margin-top: 5.5rem;
}

.prose p,
.prose li {
  font-size: 1.02rem;
}

.prose hr {
  border: 0;
  border-top: 1px solid #d0cbc3;
  margin: 1.75rem 0;
}

.prose strong {
  font-weight: 700;
}

.prose ul,
.prose ol {
  padding-left: 1.2rem;
}

.prose li + li {
  margin-top: 0.35rem;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0 1.4rem;
  font-size: 0.95rem;
}

.prose th,
.prose td {
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  padding: 0.7rem 0.55rem;
}

.prose th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 700;
}

.prose code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.88em;
  background: var(--code);
  padding: 0.1em 0.35em;
}

.prose pre {
  overflow-x: auto;
  background: #171417;
  color: #f5f0ea;
  padding: 1rem 1.1rem;
  margin: 1.1rem 0 1.4rem;
  font-size: 0.82rem;
  line-height: 1.45;
}

.prose pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: inherit;
}

.prose a {
  font-weight: 600;
}

.site-foot {
  margin-top: 1.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.site-foot code {
  font-size: 0.85em;
  background: var(--code);
  padding: 0.1em 0.35em;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

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

@keyframes hero-in {
  from {
    opacity: 0;
    transform: scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (min-width: 980px) {
  .page-shell {
    grid-template-columns: var(--outline) minmax(0, var(--max));
    justify-content: center;
    gap: 2rem;
  }

  .outline {
    display: block;
    position: sticky;
    top: 4.75rem;
    max-height: calc(100vh - 5.5rem);
    overflow-y: auto;
    padding: 0.25rem 0.35rem 1rem 0;
    scrollbar-width: thin;
  }

  .topnav {
    display: flex;
  }

  .article__head {
    grid-template-columns: 1fr auto;
    align-items: start;
  }

  .expert {
    grid-template-columns: 0.9fr 1.3fr 1fr;
    align-items: center;
  }

  .hero {
    min-height: 16.5rem;
    padding: 2.8rem 2rem;
  }

  .prose {
    --prose-pad-x: 2.1rem;
    padding: 2rem var(--prose-pad-x) 2.5rem;
  }

  .chunk-edit {
    top: 0.45rem;
    right: auto;
    left: calc(100% + var(--prose-pad-x) + 0.95rem);
    background: #f3f0ea;
    border-color: #cfc9c0;
    color: #555;
  }

  .chunk-edit::before {
    content: "";
    position: absolute;
    top: 50%;
    left: -5px;
    width: 8px;
    height: 8px;
    background: #f3f0ea;
    border-left: 1px solid #cfc9c0;
    border-bottom: 1px solid #cfc9c0;
    transform: translateY(-50%) rotate(45deg);
  }

  .chunk-edit:hover {
    background: #fff;
    color: var(--accent-deep);
    border-color: var(--accent);
  }

  .chunk-edit:hover::before {
    background: #fff;
    border-color: var(--accent);
  }
}

@media (max-width: 979px) {
  .page-shell {
    max-width: var(--max);
  }
}

@media (max-width: 640px) {
  .stats {
    grid-template-columns: repeat(3, 1fr);
  }

  .topbar__badge {
    display: none;
  }
}

/* Правки кусков Markdown */
.md-chunk {
  position: relative;
  overflow: visible;
}

.chunk-edit {
  position: absolute;
  top: 0.15rem;
  right: 0;
  z-index: 3;
  width: 1.7rem;
  height: 1.7rem;
  padding: 0;
  border: 1px solid #cfc9c0;
  background: #fff;
  color: #5a5a5a;
  font: inherit;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.chunk-edit__mark {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1;
}

.chunk-edit:hover {
  color: var(--accent-deep);
  border-color: var(--accent);
}

.edit-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(18, 18, 18, 0.42);
}

.edit-modal {
  position: fixed;
  z-index: 55;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(34rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  padding: 1.25rem 1.25rem 1.1rem;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.18);
}

.edit-modal--wide {
  width: min(48rem, calc(100vw - 2rem));
}

.edit-modal h2 {
  margin: 0 0 0.4rem;
  font-family: var(--display);
  font-size: 1.45rem;
  padding-right: 2rem;
}

.edit-hint {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.edit-label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

#edit-markdown,
#edit-token {
  width: 100%;
  font: inherit;
  font-size: 1rem;
  line-height: 1.45;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  margin-bottom: 0.85rem;
}

#edit-markdown {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.9rem;
  resize: vertical;
  min-height: 16rem;
}

#edit-markdown:focus,
#edit-token:focus {
  outline: 2px solid rgba(214, 31, 38, 0.25);
  border-color: var(--accent);
}

.edit-status {
  margin: 0.75rem 0 0;
  font-size: 0.92rem;
  color: var(--accent-deep);
}

.edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1rem;
}

.edit-btn {
  font: inherit;
  font-weight: 700;
  border: 1px solid var(--line);
  padding: 0.55rem 1rem;
  cursor: pointer;
  background: #fff;
}

.edit-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.edit-btn--ghost:hover {
  background: var(--code);
}

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

.edit-btn--primary:hover {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
}

body.edit-open {
  overflow: hidden;
}
