.sago-toc {
  --sago-toc-border: #dfe5eb;
  --sago-toc-primary-soft: color-mix(in srgb, var(--primary-color) 10%, #fff);
  --sago-toc-primary-border: color-mix(in srgb, var(--primary-color) 34%, #fff);
  box-sizing: border-box;
  width: var(--sago-toc-width, 100%);
  max-width: 100%;
  margin: 24px 0;
  border: 1px solid var(--sago-toc-border);
  border-radius: 6px;
  background: #fff;
  color: #1f2937;
}

.sago-toc__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 0 16px;
  border-bottom: 1px solid var(--sago-toc-border);
}

.sago-toc__panel > .sago-toc__header {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--sago-toc-border);
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: left;
}

.sago-toc__panel > .sago-toc__header i {
  margin-left: auto;
  color: var(--primary-color);
  transition: transform 220ms ease;
}

.sago-toc__header strong { font-size: 16px; }

.sago-toc-floating {
  display: none;
}

.sago-toc__floating-toggle,
.sago-toc__floating-close,
.sago-toc__back-to-top {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  cursor: pointer;
}

.sago-toc__floating-toggle {
  display: grid;
  flex: 0 0 48px;
  min-width: 48px;
  min-height: 48px;
  max-width: 48px;
  max-height: 48px;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1px solid var(--sago-toc-border);
  border-radius: 999px !important;
  background: #fff;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.16);
  color: var(--primary-color);
  font-size: 22px;
  line-height: 1;
}

.sago-toc__back-to-top {
  display: grid;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  min-width: 42px;
  min-height: 42px;
  place-items: center;
  border: 1px solid var(--sago-toc-border);
  border-radius: 999px !important;
  background: #fff;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.14);
  color: var(--primary-color);
  font-size: 20px;
}

.sago-toc__list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 14px 16px;
  max-height: 4000px;
  overflow: hidden;
  list-style: none;
  opacity: 1;
  transition: max-height 280ms ease, opacity 180ms ease, padding 280ms ease;
}

.sago-toc__panel > .sago-toc__list {
  max-height: var(--sago-toc-max-height, 520px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: var(--primary-color) transparent;
  scrollbar-width: thin;
}

.sago-toc__panel > .sago-toc__list::-webkit-scrollbar {
  width: 6px;
}

.sago-toc__panel > .sago-toc__list::-webkit-scrollbar-thumb {
  border-radius: 99px;
  background: var(--primary-color);
}

.sago-toc__item {
  padding-left: calc(var(--sago-toc-depth) * 16px);
  font-size: 14px;
  line-height: 1.45;
}

.sago-toc__number {
  display: inline;
  margin-right: 4px;
  color: var(--primary-color);
  font-weight: 600;
}

.sago-toc__item a { color: inherit; }
.sago-toc__item a:hover,
.sago-toc__item a.is-active {
  color: var(--primary-color);
}

.sago-toc-heading-highlight {
  animation: sago-toc-heading-highlight 1100ms ease-out;
}

@keyframes sago-toc-heading-highlight {
  0%, 55% {
    background-color: color-mix(in srgb, var(--primary-color) 14%, transparent);
    box-shadow: inset 4px 0 0 var(--primary-color);
  }

  100% {
    background-color: transparent;
    box-shadow: inset 4px 0 0 transparent;
  }
}

.sago-toc--style-list {
  border-color: #e6ebf2;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

.sago-toc--style-list .sago-toc__header {
  background: #fbfdff;
}

.sago-toc--style-list .sago-toc__list {
  gap: 0;
  padding: 6px 16px;
}

.sago-toc--style-list .sago-toc__item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-height: 42px;
  padding: 9px 0 9px calc(var(--sago-toc-depth) * 16px);
  border-bottom: 1px solid #edf1f5;
}

.sago-toc--style-list .sago-toc__item:last-child {
  border-bottom: 0;
}

.sago-toc--style-list .sago-toc__number {
  display: grid;
  flex: 0 0 24px;
  width: 24px;
  height: 24px;
  margin: 0;
  place-items: center;
  border-radius: 3px;
  background: var(--sago-toc-primary-soft);
  color: var(--primary-color);
  font-size: 12px;
}

.sago-toc--style-list .sago-toc__item a {
  display: flex;
  flex: 1;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-top: 2px;
}

.sago-toc--style-list .sago-toc__item a::after {
  content: '›';
  color: var(--primary-color);
  font-size: 20px;
  line-height: 16px;
}

.sago-toc--style-list .sago-toc__item a.is-active {
  background: transparent;
}

.sago-toc--style-timeline {
  border-color: var(--sago-toc-primary-border);
}

.sago-toc--style-timeline .sago-toc__header {
  border-bottom: 0;
}

.sago-toc--style-timeline .sago-toc__list {
  position: relative;
  gap: 0;
  padding: 4px 18px 14px 44px;
  background: linear-gradient(var(--sago-toc-primary-border), var(--sago-toc-primary-border)) 28px 0 / 1px 100% no-repeat;
}

.sago-toc--style-timeline .sago-toc__list::before {
  display: none;
}

.sago-toc--style-timeline .sago-toc__item {
  position: relative;
  min-height: 32px;
  padding: 6px 0 6px calc(var(--sago-toc-depth) * 14px);
      margin-left: 0px;
}

.sago-toc--style-timeline .sago-toc__item::before {
  position: absolute;
  z-index: 1;
  top: 13px;
  left: -20px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary-color);
  content: '';
}

.sago-toc--style-timeline .sago-toc__number {
  color: var(--primary-color);
}

.sago-toc--style-timeline .sago-toc__item a.is-active {
  background: var(--sago-toc-primary-soft);
  color: var(--primary-color);
}

.sago-toc__item a.is-active {
  display: inline;
  border-radius: 3px;
  background: var(--sago-toc-primary-soft);
  box-decoration-break: clone;
  font-weight: 700;
}

.sago-toc__item.is-active > .sago-toc__number,
.sago-toc__item.is-active > a,
.sago-toc-floating .sago-toc__item.is-active > a {
  color: var(--primary-color) !important;
  font-weight: 700;
}

.sago-toc__item.is-active > a {
  background: var(--sago-toc-primary-soft);
}

.sago-toc.is-collapsed .sago-toc__panel > .sago-toc__header { border-bottom-color: transparent; margin-bottom: 0; }
.sago-toc.is-collapsed .sago-toc__list { max-height: 0; padding-top: 0; padding-bottom: 0; overflow: hidden; opacity: 0; pointer-events: none; }
.sago-toc.is-collapsed .sago-toc__panel > .sago-toc__header i { transform: rotate(180deg); }

.sago-toc-floating.is-visible {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  position: fixed;
  z-index: 999;
}

.sago-toc-floating.is-visible .sago-toc__floating-toggle {
  display: grid;
  place-items: center;
}

.sago-toc-floating.is-visible.is-open .sago-toc__floating-panel {
  display: flex;
  flex-direction: column;
  position: fixed;
  z-index: 998;
  width: min(360px, calc(100vw - 104px));
  max-height: min(70vh, 620px);
  overflow: hidden;
  border: 1px solid var(--sago-toc-border);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 16px 42px rgba(15, 23, 42, 0.2);
}

.sago-toc__floating-panel,
.sago-toc__floating-panel .sago-toc__header {
  color: #1f2937;
}

.sago-toc__floating-panel .sago-toc__item a {
  color: #1f2937 !important;
}

.sago-toc__floating-panel .sago-toc__item a:hover,
.sago-toc__floating-panel .sago-toc__item a.is-active {
  color: var(--primary-color) !important;
}

.sago-toc__floating-panel {
  display: none;
}

.sago-toc__floating-panel .sago-toc__header {
  flex: 0 0 auto;
  background: #fff;
}

.sago-toc__floating-panel .sago-toc__list {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sago-toc__floating-close {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--primary-color);
  font-size: 20px;
}

.sago-toc-floating--desktop-left-center.is-visible {
  top: 50%;
  left: 20px;
  transform: translateY(-50%);
}

.sago-toc-floating--desktop-left-top.is-visible {
  top: 24px;
  left: 20px;
}

.sago-toc-floating--desktop-right-top.is-visible {
  top: 24px;
  right: 20px;
}

.sago-toc-floating--desktop-right-center.is-visible {
  top: 50%;
  right: 20px;
  transform: translateY(-50%);
}

.sago-toc-floating--desktop-left-bottom.is-visible {
  bottom: 24px;
  left: 20px;
}

.sago-toc-floating--desktop-right-bottom.is-visible {
  right: 20px;
  bottom: 24px;
}

.sago-toc-floating--desktop-left-center.is-visible.is-open .sago-toc__floating-panel,
.sago-toc-floating--desktop-left-bottom.is-visible.is-open .sago-toc__floating-panel,
.sago-toc-floating--desktop-left-top.is-visible.is-open .sago-toc__floating-panel {
  left: 80px;
}

.sago-toc-floating--desktop-right-center.is-visible.is-open .sago-toc__floating-panel,
.sago-toc-floating--desktop-right-bottom.is-visible.is-open .sago-toc__floating-panel,
.sago-toc-floating--desktop-right-top.is-visible.is-open .sago-toc__floating-panel {
  right: 80px;
}

.sago-toc-floating--desktop-left-center.is-visible.is-open .sago-toc__floating-panel,
.sago-toc-floating--desktop-right-center.is-visible.is-open .sago-toc__floating-panel {
  top: 50%;
  transform: translateY(-50%);
}

.sago-toc-floating--desktop-left-bottom.is-visible.is-open .sago-toc__floating-panel,
.sago-toc-floating--desktop-right-bottom.is-visible.is-open .sago-toc__floating-panel {
  bottom: 84px;
}

.sago-toc-floating--desktop-left-top.is-visible.is-open .sago-toc__floating-panel,
.sago-toc-floating--desktop-right-top.is-visible.is-open .sago-toc__floating-panel {
  top: 84px;
}

@media (min-width: 850px) {
  .sago-toc--desktop-floating { display: none; }
}

@media (max-width: 849px) {
  .sago-toc { width: 100%; }

  .sago-toc--mobile-floating { display: none; }

  .sago-toc-floating.is-visible.is-open .sago-toc__floating-panel {
    width: min(360px, calc(100vw - 40px));
    max-height: min(65vh, 520px);
  }

  .sago-toc-floating--mobile-left-center.is-visible {
    top: 50%;
    left: 12px;
    right: auto;
    bottom: auto;
    transform: translateY(-50%);
  }

  .sago-toc-floating--mobile-left-top.is-visible {
    top: 16px;
    left: 12px;
    right: auto;
    bottom: auto;
    transform: none;
  }

  .sago-toc-floating--mobile-right-top.is-visible {
    top: 16px;
    left: auto;
    right: 12px;
    bottom: auto;
    transform: none;
  }

  .sago-toc-floating--mobile-right-center.is-visible {
    top: 50%;
    left: auto;
    right: 12px;
    bottom: auto;
    transform: translateY(-50%);
  }

  .sago-toc-floating--mobile-left-bottom.is-visible {
    bottom: 16px;
    left: 12px;
    right: auto;
    top: auto;
    transform: none;
  }

  .sago-toc-floating--mobile-right-bottom.is-visible {
    top: auto;
    left: auto;
    right: 12px;
    bottom: 16px;
    transform: none;
  }

  .sago-toc-floating--mobile-left-center.is-visible.is-open .sago-toc__floating-panel,
  .sago-toc-floating--mobile-left-bottom.is-visible.is-open .sago-toc__floating-panel,
  .sago-toc-floating--mobile-left-top.is-visible.is-open .sago-toc__floating-panel {
    left: 20px;
    right: auto;
  }

  .sago-toc-floating--mobile-right-center.is-visible.is-open .sago-toc__floating-panel,
  .sago-toc-floating--mobile-right-bottom.is-visible.is-open .sago-toc__floating-panel,
  .sago-toc-floating--mobile-right-top.is-visible.is-open .sago-toc__floating-panel {
    left: auto;
    right: 20px;
  }

  .sago-toc-floating--mobile-left-center.is-visible.is-open .sago-toc__floating-panel,
  .sago-toc-floating--mobile-right-center.is-visible.is-open .sago-toc__floating-panel {
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
  }

  .sago-toc-floating--mobile-left-bottom.is-visible.is-open .sago-toc__floating-panel,
  .sago-toc-floating--mobile-right-bottom.is-visible.is-open .sago-toc__floating-panel {
    top: auto;
    bottom: 76px;
    transform: none;
  }

  .sago-toc-floating--mobile-left-top.is-visible.is-open .sago-toc__floating-panel,
  .sago-toc-floating--mobile-right-top.is-visible.is-open .sago-toc__floating-panel {
    top: 76px;
    bottom: auto;
    transform: none;
  }
}
