html[data-theme="dark"] .kratos-cover.kratos-cover-2 {
  background-position: center 52%;
}

.widget-kratos-about .photo-background {
  background-position: 60% 30%;
}

#main > .article-toc {
  display: none;
}

.kr-post [itemprop="articleBody"] :is(h1, h2, h3, h4, h5, h6)[id] {
  scroll-margin-top: 72px;
}

.kratos-page-content.kr-post > .kratos-post-inner-toc {
  display: block !important;
  margin: 0 1em 1em;
  padding: 0 12px;
  border: 1px solid var(--kr-theme-border, #e9ded4);
  border-radius: 4px;
  background: var(--kr-theme-info-bg, #faf5ee);
  font-size: 14px;
}

.kratos-post-inner-toc > summary {
  display: list-item;
  padding: 8px 0;
  cursor: pointer;
}

.kratos-post-inner-toc > .toc {
  margin: 0 0 8px;
  padding-left: 4px;
}

@media (min-width: 1120px) {
  #kratos-blog-post > .container:has(> #main > .article-toc) {
    width: min(calc(100% - 72px), 1480px);
  }

  #main:has(> .article-toc) {
    --article-toc-width: clamp(210px, 19vw, 288px);
    display: grid;
    grid-template-columns: var(--article-toc-width) minmax(0, 1fr);
    gap: 20px;
    margin-inline: 0;
  }

  #main:has(> .article-toc):has(> #kratos-widget-area) {
    grid-template-columns: var(--article-toc-width) minmax(0, 1fr) clamp(240px, 22vw, 330px);
  }

  #main:has(> .article-toc)::before,
  #main:has(> .article-toc)::after {
    display: none;
  }

  #main:has(> .article-toc) > :is(.kr-main-col, #kratos-widget-area) {
    grid-row: 1;
    width: auto;
    min-width: 0;
    padding-inline: 0;
  }

  #main:has(> .article-toc) > .kr-main-col {
    grid-column: 2;
  }

  #main:has(> .article-toc) > #kratos-widget-area {
    grid-column: 3;
  }

  #main > .article-toc {
    display: block;
    grid-area: 1 / 1;
    align-self: start;
    color: var(--kr-theme-text, #35231b);
    transition: top 0.5s ease, background-color 0.3s ease-in-out;
  }

  #main > .article-toc > .widget-title {
    margin-bottom: 0;
    white-space: nowrap;
  }

  .article-toc .textwidget {
    max-height: min(60vh, 34rem);
    overflow: auto;
    scrollbar-width: thin;
    overscroll-behavior-y: contain;
  }

  #main > .article-toc :is(.toc, .toc-child) {
    margin: 0;
    padding: 0;
  }

  #main > .article-toc .toc-child {
    padding-inline-start: 8px;
  }

  #main > .article-toc .toc-item {
    position: relative;
    padding: 0;
  }

  #main > .article-toc .toc-link {
    display: block;
    padding-block: 8px;
    padding-inline: 2px 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #main > .article-toc .toc-item:not(:last-child)::after {
    content: "";
    position: absolute;
    inset-inline: 0;
    inset-block-end: 0;
    border-bottom: 1px dashed rgb(180 175 175 / 62%);
    pointer-events: none;
  }

  #main > .article-toc .toc-link[aria-current="location"] {
    background: var(--kr-theme-info-bg, #f8f3ee);
  }

  #main > .article-toc .toc-link:focus-visible {
    outline: 1px solid currentColor;
    outline-offset: -1px;
  }

  .kratos-page-content.kr-post > .kratos-post-inner-toc {
    display: none !important;
  }
}

.article-svg {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1em auto;
  border: 0;
  color-scheme: dark;
}

.kratos-page-content .code-fold {
  --code-fold-button-width: 54px;
  /* The theme's code title bar is 30px, with 10px above the first line. */
  --code-fold-preview-height: calc(40px + 2lh);
  position: relative;
  display: grid;
  grid-template-rows: minmax(var(--code-fold-preview-height), 0fr);
  margin: 20px 0;
  overflow: hidden;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.8;
  transition: grid-template-rows 260ms ease-in-out;
}

.code-fold:has(.code-fold__body > pre) {
  /* The unwrapped highlighter leaves 30px above its code. */
  --code-fold-preview-height: calc(31px + 2lh);
}

.kratos-page-content .code-fold:has(> .code-fold__toggle[aria-expanded="true"]) {
  grid-template-rows: minmax(var(--code-fold-preview-height), 1fr);
}

.code-fold > .code-fold__body {
  min-width: 0;
  min-height: 0;
  margin: 0;
  overflow: hidden;
}

.code-fold__body > :is(figure.highlight, pre) {
  margin: 0;
}

.code-fold::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 1lh;
  background: rgb(34 34 34 / 62%);
  backdrop-filter: blur(4px);
  mask-image: linear-gradient(to bottom, transparent 20%, #000);
  pointer-events: none;
  transition: opacity 180ms ease;
}

.code-fold:has(> .code-fold__toggle[aria-expanded="true"])::after {
  opacity: 0;
}

.code-fold :is(.copy-code, .code-fold__toggle) {
  position: absolute;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  top: 5px;
  width: var(--code-fold-button-width);
  height: 20px;
  padding: 0 5px;
  border: 1px solid;
  border-radius: 4px;
  background: none;
  color: #efefef;
  font: 400 12px/1 Consolas, "Courier New", monospace;
  cursor: pointer;
  opacity: 1;
}

.code-fold .copy-code {
  right: calc(var(--code-fold-button-width) + 11px);
}

.code-fold__toggle {
  right: 5px;
}

.code-fold :is(.copy-code, .code-fold__toggle):hover {
  color: #6cc;
}

.code-fold__toggle[aria-expanded="true"] .code-fold__closed,
.code-fold__toggle[aria-expanded="false"] .code-fold__open {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .kratos-page-content .code-fold,
  .code-fold::after {
    transition: none;
  }
}

/* 立绘坐标以页脚左边缘和上沿为基准。 */
#footer {
  --portrait-x: 4%; /* 相对于整个页脚宽度，从左侧向右 */
  --portrait-y: -130px; /* 从页脚上沿向上的距离 */
  --portrait-height: 480px;

  /* 手掌相对于柴犬按钮的左上角，X 向右，Y 向下。 */
  --pet-hand-x: 52%;
  --pet-hand-y: 14%;

  /* 斗笠帽檐的挂点，相对于柴犬。 */
  --pet-hat-x: 40%;
  --pet-hat-y: 20%;

  /* 武士刀挂点相对于柴犬左上角，角度正值顺时针。 */
  --pet-sword-x: 85%;
  --pet-sword-y: 64%;
  --pet-sword-width: calc(var(--portrait-height) * 0.78);
  --pet-sword-angle: 8deg;
}

.footer-pet {
  display: none;
  -webkit-user-select: none;
  user-select: none;
}

.kr-tool .footer-pet-toggle {
  display: none;
  appearance: none;
  border: 0;
  padding: 0;
}

@media (min-width: 768px) {
  .kr-tool .footer-pet-toggle:not([hidden]) {
    display: block;
  }

  .kr-tool .footer-pet-toggle[aria-pressed="true"] {
    background: #8a542f;
    opacity: 1;
  }

  #kratos-page {
    isolation: isolate;
  }

  #kratos-blog-post {
    position: relative;
    z-index: 1;
    pointer-events: none;
  }

  /* Keep cards and widgets clickable without blocking the portrait in the gaps. */
  #main > :not(.kr-main-col, #kratos-widget-area),
  .kr-main-col > *,
  #kratos-widget-area > :not(.sticky-area),
  #kratos-widget-area .sticky-area > * {
    pointer-events: auto;
  }

  #footer {
    position: relative;
    z-index: 0;
  }

  #footer .footer-pet:not([hidden]) {
    display: block;
    position: absolute;
    left: var(--portrait-x);
    bottom: calc(100% + var(--portrait-y));
    z-index: 1;
    appearance: none;
    border: 0;
    padding: 0;
    background: none;
    cursor: pointer;
    touch-action: manipulation;
  }

  .footer-pet:focus-visible,
  .footer-pet-toggle:focus-visible {
    outline: 2px solid #f2ba70;
    outline-offset: 4px;
  }

  .footer-pet__figure {
    position: relative;
    display: block;
    isolation: isolate;
  }

  .footer-pet__image {
    position: relative;
    z-index: 1;
    display: block;
    height: var(--portrait-height);
    width: auto;
    max-width: none;
    transform-origin: center bottom;
  }

  .footer-pet__prop {
    position: absolute;
    pointer-events: none;
  }

  .footer-pet__hat {
    top: var(--pet-hat-y);
    left: var(--pet-hat-x);
    width: 75%;
    z-index: 2;
  }

  .footer-pet__hat img {
    display: block;
    width: 100%;
    height: auto;
    transform: translate(-50%, -100%) rotate(-15deg);
    transform-origin: center bottom;
    filter: brightness(0.93) drop-shadow(0 2px 2px #28150e8c);
  }

  .footer-pet__sword-anchor {
    top: var(--pet-sword-y);
    left: var(--pet-sword-x);
    width: 0;
    height: 0;
    z-index: 2;
  }

  .footer-pet__sword {
    position: absolute;
    display: block;
    /* The cord is 37% across and 42% down this 3:1 PNG. */
    top: calc(var(--pet-sword-width) * -0.14);
    left: calc(var(--pet-sword-width) * -0.37);
    width: var(--pet-sword-width);
    height: auto;
    max-width: none;
    transform: rotate(var(--pet-sword-angle));
    transform-origin: 37% 42%;
    filter: drop-shadow(2px 2px 2px #140c08aa);
  }

  .footer-pet__hand {
    position: absolute;
    z-index: 1;
    top: var(--pet-hand-y);
    left: var(--pet-hand-x);
    width: clamp(70px, calc(var(--portrait-height) * 0.30), 150px);
    aspect-ratio: 1;
    transform: translate(-80%, -68%);
    /* Hand template from https://benisland.neocities.org/petpet/. */
    background: url("https://47.104.65.156:5243/d/SharkcatFileHub/stupcat/blog/site-assets/petpet-hand-fedef6b37205.png") no-repeat left top / 500% 100%;
    visibility: hidden;
    pointer-events: none;
  }

  .footer-pet.is-petting .footer-pet__hand {
    visibility: visible;
  }
}

#kratos-desktop-topnav {
  --site-nav-active-bg: #8A542F;
}

#kratos-desktop-topnav .sf-menu > li:is(:hover, :focus-within) > a {
  background-color: var(--site-nav-active-bg);
  color: #fff;
}

#kratos-desktop-topnav .sf-menu > li > ul.sub-menu {
  background-color: var(--site-nav-active-bg);
}

#kratos-desktop-topnav .sf-menu > li > ul.sub-menu::before {
  border-bottom-color: var(--site-nav-active-bg);
}

#kratos-desktop-topnav .sf-menu > li > ul.sub-menu a {
  color: #fff;
}

#kratos-desktop-topnav .sf-menu > li > ul.sub-menu a:hover {
  color: #ffe8ca;
}
