:root{
  --bg:#f6f7fb;
  --card:#ffffff;
  --text:#0f172a;
  --muted:#64748b;
  --border:#e5e7eb;
  --primary:#0ea5e9;
  --primary-2:#0284c7;
  --shadow: 0 10px 30px rgba(15, 23, 42, .08);

  --radius:16px;
  --container: 1100px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Noto Sans", "Liberation Sans", sans-serif;
}

*{ box-sizing:border-box; }
html {
  
}
html,body{ height:100%; }
body{
  margin:0;
  font-family:var(--sans);
  background:var(--bg);
  color:var(--text);
}

.container{
  width: min(var(--container), calc(100% - 32px));
  margin: 0 auto;
}
@media (max-width: 560px){
  .container{ width: calc(100% - 24px); }
}

/* header not sticky */
.topbar{
  position: static;
  background: var(--bg);
  border-bottom:1px solid var(--border);
  margin-bottom: 15px;
}
.topbar-inner{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 12px 0;
}
.brand{
  display:flex;
  gap:10px;
  align-items:baseline;
  text-decoration:none;
  color:inherit;
}
.brand-title{ font-weight:800; letter-spacing:.2px; }
.brand-sub{ color:var(--muted); font-size:13px; }

.btn{
  border:1px solid var(--border);
  background: var(--card);
  padding: 8px 10px;
  border-radius: 12px;
  font-weight: 650;
  cursor:pointer;
  text-decoration:none;
  color:inherit;
  display:inline-flex;
  align-items:center;
  gap:8px;
  font-size: 14px;
}
.btn:hover{ border-color:#cbd5e1; }
.btn-primary{
  background: var(--primary);
  border-color: var(--primary);
  color:white;
}
.btn-primary:hover{
  background: var(--primary-2);
  border-color: var(--primary-2);
}
.btn-ghost{ background:transparent; }
.btn-sm{ padding:6px 8px; border-radius:10px; font-size:13px; }

.card{
  background:var(--card);
  border:1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin: 0 0 16px 0;
}
@media (max-width:560px){
  .card{ padding: 14px; margin: 12px 0; }
}

.h1{
  margin:0 0 8px 0;
  font-size: 26px;
  line-height: 1.15;
}
@media (max-width:560px){
  .h1{ font-size: 20px; }
}

.muted{ color:var(--muted); }
.mono{ font-family:var(--mono); }

/* ---------- HOME GRID (FIX manual-tile styles) ---------- */
.grid{
  display:grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 14px;
  margin-top: 16px;
}
@media (max-width: 840px){
  .grid{ grid-template-columns: 1fr; }
}

.manual-tile{
  display:block;
  text-decoration:none;
  color:inherit;
  border:1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  background: #fbfdff;
}
.manual-tile:hover{ border-color:#cbd5e1; }
.manual-tile-title{ font-weight:900; margin-bottom:6px; }
.manual-tile-meta{ color:var(--muted); font-size:13px; margin-bottom:8px; }
.manual-tile-link{ font-family:var(--mono); color:#0b5a7a; font-size:12px; }

/* footer */
.footer{
  margin-top: 26px;
  padding: 26px 0;
  border-top:1px solid var(--border);
}
.footer-inner{
  display:flex;
  justify-content:space-between;
  align-items:center;
}

/* Manual layout */
.manual-wrap{
  position: relative;
  display:grid;
  grid-template-columns: 320px minmax(0,1fr);
  gap: 14px;
  align-items:start;
}
@media (max-width: 980px){
  .manual-wrap{ grid-template-columns: 1fr; }
}

.toc{
  position: sticky;
  top: 18px;
  border:1px solid var(--border);
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  max-height: calc(100vh - 36px);
  overflow:auto;
}
.toc-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding-bottom: 8px;
  border-bottom:1px solid var(--border);
}
.toc-title{ font-weight: 800; }
.toc-close{ display:none; }

.toc-body{ padding-top:10px; display:flex; flex-direction:column; gap:6px; }
.toc-item{
  text-decoration:none;
  color:inherit;
  padding: 8px 10px;
  border-radius: 10px;
  border:1px solid transparent;
  font-size: 14px;
}
.toc-item:hover{ background:#f8fafc; border-color:#e2e8f0; }
.toc-item.active{ background:#ecfeff; border-color:#a5f3fc; }

.toc-l2{ font-weight:700; }
.toc-l3{ padding-left: 18px; color:#0f172a; }
.toc-l4{ padding-left: 30px; color:var(--muted); }

@media (max-width: 980px){
  .toc{
    position: fixed;
    z-index: 80;
    left: 10px;
    right: 10px;
    top: 10px;
    bottom: 10px;
    max-height: none;
    transform: translateY(20px);
    opacity: 0;
    pointer-events:none;
    transition: all .18s ease;
  }
  .toc.toc-open{
    transform: translateY(0);
    opacity:1;
    pointer-events:auto;
  }
  .toc-close{ display:inline-flex; }
}

.manual{ padding: 16px; }
@media (max-width:560px){
  .manual{ padding: 14px; }
}

.manual-head{
  display:flex;
  justify-content:space-between;
  gap: 10px;
  align-items:flex-start;
  padding-bottom: 10px;
  border-bottom:1px solid var(--border);
  margin-bottom: 10px;
}

.manual-head-left{ min-width:0; }
.manual-title{ margin-bottom: 4px; }
.manual-meta{ font-size: 13px; }

.manual-head-actions{
  display:flex;
  gap: 8px;
  align-items:center;
  flex-wrap:wrap;
  justify-content:flex-end;
}

.icon-btn{
  width: 34px;
  height: 34px;
  border:1px solid var(--border);
  background: var(--card);
  border-radius: 12px;
  cursor:pointer;
  display:inline-flex;
  align-items:center;
  justify-content:center;
}
.icon-btn:hover{ border-color:#cbd5e1; }

.icon{
  display:block;
  width: 18px;
  height: 18px;
  background: #0f172a;
  mask-size: contain;
  mask-repeat: no-repeat;
  mask-position: center;
  -webkit-mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;
}

/* Desktop: hide toc button */
@media (min-width: 981px){
  #tocToggle{ display:none; }
}

/* Mobile toolbar sticky */
.manual-toolbar{
  display:none;
}
@media (max-width: 980px){
  #sticky-sentinel {
    position: absolute;
    left: 0;
    right: 0;
    visibility: hidden;
    /* Сдвигаем его вверх на высоту top: 0, чтобы сработал триггер */
    top: -1px; 
    height: 1px;
  }

  .manual-toolbar {
    /* Ваши исходные стили */
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: flex-end;
    position: sticky;
    top: 0;
    z-index: 30;
    background: rgba(246,247,251,.92);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 8px;
    margin: 10px 0 12px;
    
    /* Плавный переход свойств при прилипании */
    transition: all 0.3s ease;
  }

  /* Стили, когда блок прилип */
  .manual-toolbar.is-pinned {
    /* Убираем отступы и скругления */
    border-radius: 0;
    margin-top: 0;
    border-left: none;
    border-right: none;
    
    /* Магия растягивания на всю ширину экрана, даже если блок внутри контейнера */
    width: 100vw;
    margin-left: calc(-50vw + 50%);
    margin-right: calc(-50vw + 50%);
    
    /* Небольшая коррекция паддингов, чтобы контент не прилип к краям экрана */
    padding-left: 20px;
    padding-right: 20px;
  }
  .manual-head-actions{ display:none; }
}

.manual-content{
  font-size: 16px;
  line-height: 1.75;
}
@media (max-width:560px){
  .manual-content{ font-size: 15px; }
}

.manual-content p{ margin: 12px 0; }
.manual-content h1,
.manual-content h2,
.manual-content h3,
.manual-content h4{
  margin: 18px 0 10px 0;
  line-height:1.25;
}
.manual-content h2{ font-size: 21px; padding-top: 6px; }
.manual-content h3{ font-size: 17px; }
.manual-content h4{ font-size: 15px; color:#0f172a; }
@media (max-width:560px){
  .manual-content h2{ font-size: 18px; }
  .manual-content h3{ font-size: 16px; }
}

.manual-content a{ color: var(--primary-2); }

.manual-content code{
  font-family: var(--mono);
  font-size: 13px;
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 8px;
}

.manual-content pre{
  overflow:auto;
  padding: 14px;
  border-radius: 14px;
  border:1px solid var(--border);
  background: #0b1220;
  color:#e5e7eb;
}
.manual-content pre code{ background: transparent; padding: 0; color: inherit; }

/* callouts */
.callout{
  border-radius: 14px;
  border: 1px solid var(--border);
  padding: 12px 14px;
  margin: 14px 0;
}
.callout-title{ font-weight: 900; margin-bottom: 6px; }
.callout-warning{ background: #fff7ed; border-color:#fed7aa; }
.callout-info{ background: #eff6ff; border-color:#bfdbfe; }
.callout-tip{ background: #ecfdf5; border-color:#a7f3d0; }

mark{
  background: #fde68a;
  color: inherit;
  padding: 0 3px;
  border-radius: 4px;
}

/* Image blocks */
figure.md-image{
  margin: 14px 0;
  clear: both;
}

figure.md-image .img-frame{
  overflow:hidden;
}

figure.md-image.with-border .img-frame{ border:5px solid var(--border); border-radius: 14px;}
figure.md-image.with-shadow .img-frame{ box-shadow: 0 10px 30px rgba(15,23,42,.10); }

figure.md-image img{
  display:block;
  width:100%;
  height:auto;
}

figure.md-image.mh-sm .img-frame{ max-height: 260px; }
figure.md-image.mh-md .img-frame{ max-height: 420px; }
figure.md-image.mh-lg .img-frame{ max-height: 560px; }
figure.md-image.mh-none .img-frame{ max-height: none; }

figure.md-image.crop img{
  height: 100%;
  max-height: inherit;
  object-fit: cover;
  object-position: top center;
}
figure.md-image.no-crop img{ object-fit: contain; }

figure.md-image.w-100{ width: 100%; }
figure.md-image.w-75{ width: 75%; }
figure.md-image.w-50{ width: 50%; }
figure.md-image.w-25{ width: 25%; }

figure.md-image.align-center{ margin-left:auto; margin-right:auto; }
figure.md-image.align-left{ margin-left:0; margin-right:auto; }
figure.md-image.align-right{ margin-left:auto; margin-right:0; }

figure.md-image.wrap.align-left{ float:left; margin-right: 14px; }
figure.md-image.wrap.align-right{ float:right; margin-left: 14px; }
figure.md-image.wrap{ margin-top: 6px; margin-bottom: 6px; }

figure.md-image figcaption{
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

/* mobile: always 100% and no wrap */
@media (max-width: 980px){
  figure.md-image{
    width: 100% !important;
    float: none !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
}

/* Search bottom bar */
.searchbar{
  position: fixed;
  left: 0;
  right: 0;
  bottom: -120px;
  z-index: 90;
  transition: bottom .18s ease;
  padding: 10px;
  pointer-events:none;
}
.searchbar.open{
  bottom: 0;
  pointer-events:auto;
}
.searchbar-inner{
  width: min(var(--container), calc(100% - 20px));
  margin: 0 auto;
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 10px;
  display:flex;
  gap: 10px;
  align-items:center;
}
.searchbar input{
  flex:1;
  border:1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  outline:none;
  font-size: 14px;
}
.searchbar input:focus{
  border-color:#93c5fd;
  box-shadow:0 0 0 3px rgba(59,130,246,.12);
}

/* Lightbox */
.lightbox{
  position: fixed;
  inset: 0;
  z-index: 100;
  display:none;
}
.lightbox.open{ display:block; }

.lightbox-backdrop{
  position:absolute;
  inset:0;
  background: rgba(0,0,0,.55);
}

.lightbox-inner{
  position:absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%,-50%);
  width: min(92vw, 1100px);
  max-height: 88vh;
  background: #0b1220;
  border-radius: 14px;
  overflow:hidden;
  box-shadow: 0 30px 80px rgba(0,0,0,.4);
  padding: 12px;
}

.lightbox-inner img{
  width: 100%;
  height: auto;
  max-height: 74vh;
  object-fit: contain;
  display:block;
  border-radius: 10px;
}

.lightbox-caption{
  color: rgba(255,255,255,.78);
  font-size: 12px;
  margin-top: 10px;
}

.lightbox-x{
  position:absolute;
  top: 8px;
  right: 10px;
  border:none;
  background: transparent;
  color: white;
  font-size: 28px;
  cursor:pointer;
}

/* Print */
@media print{
  .topbar, .footer, .toc, .manual-head-actions, .manual-toolbar, .searchbar, .lightbox{ display:none !important; }
  body{ background:white; }
  .card{ box-shadow:none; border:none; padding:0; margin:0; }
  .manual-wrap{ display:block; }
}

/* Нормальная рамка/тень на контейнер, а не на img */
.md-image .img-frame{
}

.md-image.with-border .img-frame{
  border:1px solid var(--border);
}

.md-image.with-shadow .img-frame{
  box-shadow: var(--shadow);
}

/* Выравнивание (работает при ширине меньше 100%) */
.md-image.align-center{ margin-left:auto; margin-right:auto; }
.md-image.align-left{ margin-right:auto; }
.md-image.align-right{ margin-left:auto; }

/* Max-height режимы */
.md-image.no-crop img{
  width:100%;
  height:auto;
  object-fit:contain;
}

.md-image.no-crop.mh-sm img{ max-height:240px; }
.md-image.no-crop.mh-md img{ max-height:420px; }
.md-image.no-crop.mh-lg img{ max-height:620px; }
.md-image.no-crop.mh-none img{ max-height:none; }

.md-image.crop .img-frame{ height:420px; }
.md-image.crop.mh-sm .img-frame{ height:240px; }
.md-image.crop.mh-md .img-frame{ height:420px; }
.md-image.crop.mh-lg .img-frame{ height:620px; }
.md-image.crop.mh-none .img-frame{ height:auto; }

.md-image.crop img{
  width:100%;
  height:100%;
  object-fit:cover;
}

/* Подпись */
.md-image figcaption{
  margin-top:8px;
  font-size:13px;
  color:var(--muted);
}

.md-image.wrap{float:none!important}
.md-image.wrap.align-left{margin-left:0!important;margin-right:auto!important}
.md-image.wrap.align-right{margin-left:auto!important;margin-right:0!important}

.manual-tile-desc{margin:8px 0;color:var(--muted);font-size:13px;line-height:1.45}
.manual-content blockquote{margin:14px 0;padding:10px 14px;border-left:4px solid var(--primary);background:#f0f9ff;border-radius:12px}
.manual-content blockquote p{margin:8px 0}
.manual-content pre{background:#f8fafc;color:var(--text);border:1px solid var(--border)}
.manual-content pre code{background:transparent;color:inherit}

.pswp__custom-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 14px;
  color: #fff;
  background: rgba(0,0,0,.45);
  font-size: 14px;
  line-height: 1.35;
}

.pswp__img {
  width: auto !important;
  height: auto !important;
  object-fit: contain !important;
}