$pdf-columns: true !default;
@if $pdf-columns and $column-count > 1 {

    // Columns

    $page-body-width: $page-width - $margin-inside - $margin-outside !default;
    $columns-gap-default: $paragraph-indent !default;
    $columns-1-gap: 0 !default;
    $columns-2-gap: $columns-gap-default !default;
    $columns-3-gap: $columns-gap-default !default;
    $columns-1-width: $page-body-width !default;
    $columns-2-width: ($page-body-width - $columns-2-gap) / 2 !default;
    $columns-3-width: ($page-body-width - $columns-3-gap * 2) / 3 !default;

    @if $multi-column-pages {

        @each $page-style in $multi-column-pages {

            .#{$page-style} {

                .content {
                    column-count: $column-count;
                    column-gap: $columns-gap-default;

                    // When column-count is 1, Prince collapses
                    // margin-top on the first heading in a div,
                    // which we don't want. So we use auto,
                    // which should default to one column anyway,
                    // but doesn't cause the unexpected behaviour.

                    @if $column-count == 1 {
                        column-count: auto;
                    }

                    // column-fill: auto; // do not balance columns
                    // Allow document-level overrides by
                    // columns-x class on body element
                    .columns-1 & {
                        column-count: 1;
                        column-gap: $columns-1-gap;
                    }
                    .columns-2 & {
                        column-count: 2;
                        column-gap: $columns-2-gap;
                    }
                    .columns-3 & {
                        column-count: 3;
                        column-gap: $columns-3-gap;
                    }
                }
                @if $column-count == 1 {
                    .figure.columns-1 {
                        width: $columns-1-width;
                    }
                }
                .columns-1 {
                    .figure.columns-1 {
                        width: $columns-1-width;
                    }
                }
                @if $column-count == 2 {
                    .figure.columns-1 {
                        width: $columns-2-width;
                    }
                    .figure.columns-2 {
                        width: $columns-2-width * 2 + $columns-2-gap;
                    }
                }
                .columns-2 {
                    .figure.columns-1 {
                        width: $columns-2-width;
                    }
                    .figure.columns-2 {
                        width: $columns-2-width * 2 + $columns-2-gap;
                    }
                }
                @if $column-count == 3 {
                    .figure.columns-1 {
                        width: $columns-3-width;
                    }
                    .figure.columns-2 {
                        width: $columns-3-width * 2 + $columns-2-gap;
                    }
                }
                .columns-3 {
                    .figure.columns-1 {
                        width: $columns-3-width;
                    }
                    .figure.columns-2 {
                        width: $columns-3-width * 2 + $columns-2-gap;
                    }
                }
            }
        }
    }
}
