/* ==========================================================================
   Listicle Power Mode
   ========================================================================== */

/* Wrapper & Counters */
.listicle-wrapper {
    margin-block: 0;
}

.listicle-wrapper.has-countdown {
    counter-reset: listicle-counter;
}

/* Reverse Order Counter Logic */
.listicle-wrapper.has-countdown.order-desc {
    /* Start from total + 1 so the first decrement gives total */
    counter-reset: listicle-counter calc(var(--total-items) + 1);
}

.listicle-wrapper.has-countdown .listicle-item {
    counter-increment: listicle-counter;
}

.listicle-wrapper.has-countdown.order-desc .listicle-item {
    counter-increment: listicle-counter -1;
}

/* Render the counter on the separator (H2-H5) */
.listicle-wrapper.has-countdown .listicle-item :is(h2, h3, h4, h5)::before {
    content: counter(listicle-counter) " |";
    color: var(--accent);
    margin-right: var(--size-2);
}

/* Type: Vertical */
.listicle-wrapper.type-vertical {
    display: flex;
    flex-direction: column;
    gap: var(--size-6);
}

/* Type: Horizontal (Embla) */
.listicle-wrapper.type-horizontal.embla {
    overflow: hidden;
    position: relative;
    /* Ensure navigation is outside but nearby */
}

/* Missing Viewport Logic */
.listicle-wrapper.type-horizontal .embla__viewport {
    overflow: hidden;
    width: 100%;
}

.listicle-wrapper.type-horizontal .embla__container {
    display: flex;
    height: auto;
    touch-action: pan-y pinch-zoom;
    margin-left: 0;
}

.listicle-wrapper.type-horizontal .embla__slide {
    flex: 0 0 100%;
    min-width: 0;
    padding-inline: var(--size-2);
}

/* Progress Bar (Reuse/Match Gallery style reference) */
.embla__progress {
    position: relative;
    width: 100%;
    height: 4px;
    background-color: var(--surface-2);
    /* Track color */
    margin-top: var(--size-3);
    border-radius: 2px;
    overflow: hidden;
}

.embla__progress__bar {
    height: 100%;
    background-color: var(--text);
    /* Fill color */
    width: 0;
    /* Updated by JS */
    min-width: 2px;
    /* Visibility */
    transition: width 0.1s linear;
}

/* Alignment Overrides (Copied from gallery-slider.css) */
.embla__progress--left,
.embla__progress--center,
.embla__progress--right {
    background-color: transparent;
    /* Remove full width track background from container */
    display: flex;
    width: 100%;
    overflow: visible;
    /* Allow flex children */
}

.embla__progress--left {
    justify-content: flex-start;
}

.embla__progress--center {
    justify-content: center;
}

.embla__progress--right {
    justify-content: flex-end;
}

.embla__progress--left,
.embla__progress--center,
.embla__progress--right {
    /* Make the CONTAINER the fixed-width track */
    flex: 0 0 200px;
    max-width: 200px;
    /* Fix width */
    background-color: var(--surface-2);
    /* Track color back on */
    display: block;
    /* Not flex anymore, it's the track */
    margin-top: var(--size-3);
}

.embla__progress--left {
    margin-right: auto;
}

.embla__progress--center {
    margin-inline: auto;
}

.embla__progress--right {
    margin-left: auto;
}

/* Top Header Bar */
.listicle-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin:0 1em;
    gap: var(--size-4);
    border-bottom: var(--border-muted);
    padding-bottom: var(--size-1);
}

.listicle-current-title :is(h2, h3, h4, h5) {
    margin: 0;
    font-size: var(--font-size-4);
    line-height: 1.2;
}

.listicle-counter-number {
    color: var(--accent);
    font-weight: bold;
}

/* Hide the title inside the slide since it's now in the header */
.listicle-wrapper.type-horizontal .listicle-slide-title {
    display: none;
}

/* Top-Right Navigation (Inside Header now) */
.listicle-nav {
    display: flex;
    justify-content: flex-end;
    gap: var(--size-2);
    /* margin-block-end removed as it's in flex container */
}

.listicle-prev,
.listicle-next {
    position: relative;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    transition: color 0.2s ease, transform 0.2s ease;
    box-shadow: none;
    padding: 0;
    z-index: 2;
}

/* Circular glow effect */
.listicle-prev::after,
.listicle-next::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--accent);
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: -1;
}

.listicle-prev:hover,
.listicle-next:hover {
    color: var(--accent);
    background: transparent;
    transform: scale(1.1);
    /* Slight zoom */
}

.listicle-prev:hover::after,
.listicle-next:hover::after {
    opacity: 0.15;
    /* Glow opacity */
}

.listicle-prev i,
.listicle-next i {
    font-size: 1.5rem;
    /* Match gallery-slider icon size */
    line-height: 1;
}

/* ==========================================================================
   Mobile Responsiveness
   ========================================================================== */

@media (max-width: 600px) {
    .listicle-header {
        flex-wrap: wrap;
        margin: 0 10px;
        padding-inline: 0;
        gap: var(--size-2);
        max-width: 100%;
    }

    .listicle-current-title :is(h2, h3, h4, h5) {
        font-size: var(--size-fluid-2);
        word-break: break-word;
    }

    .listicle-nav {
        gap: 0;
    }

    .listicle-prev i,
    .listicle-next i {
        font-size: 1rem;
    }

    .listicle-wrapper.type-horizontal {
        max-width: calc(100vw - var(--gutter) * 2);
    }


    /* Ensure content inside slides doesn't blow out width */
    .listicle-wrapper.type-horizontal .embla__slide img,
    .listicle-wrapper.type-horizontal .embla__slide video,
    .listicle-wrapper.type-horizontal .embla__slide iframe,
    .listicle-wrapper.type-horizontal .embla__slide table,
    .listicle-wrapper.type-horizontal .embla__slide pre {
        max-width: 100%;
        height: auto;
    }

    .listicle-wrapper.type-horizontal .embla__container {
        margin-bottom: 0;
    }
}