/* =========================================================
   História Timeline — slide + text view
========================================================= */

/* Lenis base rules. Bootstrap's `scroll-behavior: smooth` makes ScrollTrigger's
   refresh measure mid-animation, which leaves every start/end point wrong. */
html.lenis,
html.lenis body {
    height: auto;
}

.lenis.lenis-smooth {
    scroll-behavior: auto !important;
}

.lenis.lenis-stopped {
    overflow: hidden;
}

.historia-timeline {
    --historia-bg: #ffffff;
    --historia-ink: #303030;
    --historia-muted: #6b6b6b;
    --historia-dark: var(--dark-blue, #1003A3);
    --historia-surface: #0f0e2e;
    --historia-panel: #17162f;
    position: relative;
    width: 100%;
    background: var(--historia-bg);
    color: var(--historia-ink);
    isolation: isolate;
}

.historia-timeline.is-text-open {
    /* keep layout; modal handles lock */
}

/* Progress */
.historia-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 90;
    height: 2px;
    pointer-events: none;
    background: rgba(16, 3, 163, 0.12);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.historia-timeline.is-sliding .historia-progress {
    opacity: 1;
}

.historia-progress__bar {
    display: block;
    height: 100%;
    width: 100%;
    background: var(--dark-blue, #1003A3);
    transform: scaleX(0);
    transform-origin: left center;
    will-change: transform;
}

/* Slide stage */
.historia-slide {
    position: relative;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    overflow: hidden; /* prevent page scrollbars while layers travel */
    background: var(--historia-bg);
}

.historia-slide__stage {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: visible;
}

.historia-scene {
    position: absolute;
    inset: 0;
    opacity: 1;
    visibility: visible;
    pointer-events: none;
    overflow: visible;
}

/* Scenes and the layer wrapper must not set z-index: that would create a stacking
   context and trap every image below the year track. Layers stack against the
   year track (z 5) and the caption (z 10) directly. */
.historia-scene.is-active {
    pointer-events: auto;
}

.historia-scene__layers {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: visible;
}

/* Layers: position is the image centre on screen; width is % of the viewport width. */
.historia-layer {
    position: absolute;
    left: var(--layer-x, 25%);
    top: var(--layer-y, 65%);
    z-index: var(--layer-z, 2);
    width: calc(var(--layer-w, 30) * 1vw);
    transform: translate(-50%, -50%);
    overflow: visible;
}

.historia-layer__drift,
.historia-layer__inner {
    position: relative;
    display: block;
    width: 100%;
    overflow: visible;
    will-change: transform, opacity, filter;
}

.historia-layer__orient {
    display: block;
    width: 100%;
    transform-origin: center center;
    /* Flip first, then rotate, so the angle matches what is set in the field. */
    transform: rotate(var(--layer-rot, 0deg)) scaleX(var(--layer-flip-x, 1)) scaleY(var(--layer-flip-y, 1));
    will-change: transform;
}

.historia-layer img {
    display: block;
    width: 100%;
    height: auto;
    max-height: 85vh;
    object-fit: contain;
    object-position: center;
}

.historia-layer--shape-circle .historia-layer__inner {
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: 50%;
}

.historia-layer--shape-circle .historia-layer__orient {
    height: 100%;
}

.historia-layer--shape-circle img {
    height: 100%;
    max-height: none;
    object-fit: cover;
}

/* Year track — YEAR ──── YEAR ──── YEAR ────, slides left scene by scene */
.historia-slide {
    --historia-rule-top: 32%;
    --historia-rule-weight: clamp(4px, 0.4vw, 7px);
    /* vw, not %: inside the year rail, % resolves against the full multi-slide rail width. */
    --historia-gutter: max(1.5rem, 3vw);
    --historia-year-size: clamp(5rem, 15vw, 18rem);
}

.historia-year-track {
    position: absolute;
    left: 0;
    top: var(--historia-rule-top);
    z-index: 5;
    transform: translateY(-50%);
    pointer-events: none;
}

.historia-year-track__rail {
    display: flex;
    flex-wrap: nowrap;
    will-change: transform;
}

.historia-year-track__item {
    display: flex;
    flex: 0 0 var(--historia-slot, 100vw);
    align-items: center;
    box-sizing: border-box;
    padding-left: var(--historia-gutter);
}

.historia-year-track__year {
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
}

/* Mask padding leaves room for Playfair's old-style descenders (3, 4, 5, 7, 9);
   the matching negative margin keeps the stacked lines at the same spacing. */
.historia-year-track__mask {
    display: block;
    overflow: hidden;
    font-size: var(--historia-year-size);
    padding: 0.1em 0.08em 0.28em;
    margin: -0.1em -0.08em -0.28em;
}

.historia-year-track__text {
    display: block;
    font-size: 1em;
    line-height: 0.86;
    font-weight: 400;
    letter-spacing: -0.02em;
    color: var(--scene-color, var(--historia-dark));
    white-space: nowrap;
    will-change: transform;
}

.historia-year-track__line {
    display: block;
    flex: 1 1 auto;
    height: var(--historia-rule-weight);
    margin-left: clamp(1rem, 2vw, 2rem);
    background: var(--scene-color, var(--historia-dark));
    transform-origin: left center;
}

/* Copy — title sits above the line, body below it */
.historia-scene__copy {
    position: absolute;
    inset: 0;
    z-index: 10;
    pointer-events: none;
}

.historia-caption {
    position: absolute;
    inset: 0;
}

.historia-caption__title,
.historia-caption__body {
    opacity: 0;
    will-change: transform, opacity, filter;
}

.historia-caption__title {
    position: absolute;
    left: 40%;
    right: var(--historia-gutter);
    bottom: calc(100% - var(--historia-rule-top) + var(--historia-rule-weight) + 1rem);
    margin: 0;
    font-family: "Playfair Display", serif;
    font-size: 40px;
    font-style: normal;
    font-weight: 500;
    line-height: normal;
    color: var(--historia-dark, #1003A3);
    pointer-events: auto;
}

.historia-caption__body {
    position: absolute;
    left: 45%;
    top: calc(var(--historia-rule-top) + var(--historia-rule-weight) + 1.75rem);
    width: min(29vw, 46rem, calc(55% - var(--historia-gutter)));
    font-size: clamp(0.95rem, 1.06vw, 1.5rem);
    line-height: 1.6;
    color: var(--historia-ink);
    pointer-events: auto;
}

.historia-caption__body > *:first-child {
    margin-top: 0;
}

.historia-caption__body > *:last-child {
    margin-bottom: 0;
}

.historia-caption__body p {
    margin: 0 0 0.75rem;
}

/* View toggle */
.historia-view-toggle {
    position: fixed;
    left: 1.25rem;
    bottom: 1.25rem;
    z-index: 100;
    display: flex;
    gap: 0.35rem;
    padding: 0.25rem;
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(16, 3, 163, 0.12);
}

.historia-view-toggle__btn {
    appearance: none;
    border: 0;
    margin: 0;
    padding: 0.55rem 0.9rem;
    background: transparent;
    color: var(--historia-muted);
    font-family: var(--font-roboto, inherit);
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: lowercase;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.historia-view-toggle__btn.is-active,
.historia-view-toggle__btn[aria-pressed="true"] {
    background: var(--historia-dark);
    color: #fff;
}

.historia-view-toggle__btn:focus-visible {
    outline: 2px solid var(--historia-dark);
    outline-offset: 2px;
}

/* Text view modal */
.historia-text-view {
    position: fixed;
    inset: 0;
    z-index: 120;
}

.historia-text-view[hidden] {
    display: none !important;
}

.historia-text-view__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(8, 6, 40, 0.45);
}

.historia-text-view__panel {
    position: absolute;
    inset: 0;
    overflow: auto;
    background: var(--historia-surface);
    color: #f4f2ee;
    -webkit-overflow-scrolling: touch;
}

.historia-text-view__header {
    position: relative;
    padding: clamp(3rem, 8vw, 6rem) clamp(1.25rem, 5vw, 4rem) 2.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.historia-text-view__breadcrumb {
    margin: 0 0 1rem;
    font-size: 0.75rem;
    letter-spacing: 0.12em;
    text-transform: lowercase;
    opacity: 0.65;
}

.historia-text-view__title {
    margin: 0 0 0.75rem;
    font-size: clamp(2.2rem, 6vw, 4.5rem);
    line-height: 0.95;
    font-weight: 700;
    letter-spacing: -0.03em;
    text-transform: lowercase;
}

.historia-text-view__tagline {
    margin: 0;
    max-width: 36rem;
    font-size: 1rem;
    line-height: 1.5;
    opacity: 0.8;
}

.historia-text-view__close {
    position: absolute;
    top: 1.25rem;
    right: 1.25rem;
    width: 2.5rem;
    height: 2.5rem;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: transparent;
    color: #fff;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
}

.historia-text-view__close:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.historia-text-view__list {
    padding: 0 clamp(1.25rem, 5vw, 4rem) 6rem;
}

.historia-text-row {
    display: grid;
    grid-template-columns: minmax(5rem, 0.2fr) minmax(0, 0.35fr) minmax(0, 0.45fr);
    gap: 1.5rem 2rem;
    padding: 2rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.historia-text-row__year {
    margin: 0;
    font-size: clamp(1.8rem, 3vw, 2.8rem);
    line-height: 1;
    font-weight: 700;
    color: var(--scene-color, #88c5e6);
}

.historia-text-row__summary {
    margin: 0;
    font-size: 1rem;
    line-height: 1.45;
    color: rgba(255, 255, 255, 0.92);
}

.historia-text-row__detail {
    font-size: 0.92rem;
    line-height: 1.65;
    color: rgba(255, 255, 255, 0.72);
}

.historia-text-row__detail-title {
    margin: 0 0 0.5rem;
    color: rgba(255, 255, 255, 0.95);
    font-weight: 500;
}

.historia-text-row__detail p {
    margin: 0 0 0.75rem;
}

.historia-text-row__detail p:last-child {
    margin-bottom: 0;
}

/* Body lock when text view open */
html.historia-text-open,
html.historia-text-open body {
    overflow: hidden;
}

/* Responsive */
/* Portrait phones/tablets: same collage, recomposed for a tall screen —
   year top-left on the rule, title under the rule, paragraph in a translucent
   panel, images filling the rest (placement from the mobile ACF fields). */
@media (max-width: 991px) {
    /* The rule sits low enough for the tallest year to clear the fixed header + logo badge. */
    .historia-slide {
        --historia-top-clear: 8.75rem;
        --historia-rule-top: calc(var(--historia-top-clear) + var(--historia-year-drop-max, var(--historia-year-size) * 0.5));
        --historia-rule-weight: 4px;
        --historia-gutter: 1.1rem;
        --historia-year-size: clamp(4.25rem, 27vw, 10rem);
    }

    .historia-year-track__line {
        margin-left: 0.75rem;
    }

    .historia-caption__title {
        left: var(--historia-gutter);
        right: var(--historia-gutter);
        bottom: auto;
        top: calc(var(--historia-rule-top) + var(--historia-year-drop, var(--historia-year-size) * 0.5) + 0.6rem);
        font-size: 40px;
    }

    .historia-caption__body {
        left: var(--historia-gutter);
        right: auto;
        top: calc(var(--historia-rule-top) + var(--historia-year-drop, var(--historia-year-size) * 0.5) + 0.6rem + 53px + 0.75rem);
        width: min(calc(100vw - var(--historia-gutter) * 2), 34rem);
        /* Leaves the lower part of the screen to the collage; overflowing text is
           scrolled through by the timeline while the slide holds. */
        max-height: max(9rem, calc(64% - var(--historia-rule-top) - var(--historia-year-drop, var(--historia-year-size) * 0.5) - 0.6rem - 53px - 0.75rem));
        overflow: hidden;
        box-sizing: border-box;
        padding: 1rem 1.1rem 1.4rem;
        -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 0.9rem, #000 calc(100% - 1.2rem), transparent 100%);
        mask-image: linear-gradient(to bottom, transparent 0, #000 0.9rem, #000 calc(100% - 1.2rem), transparent 100%);
        font-size: clamp(0.92rem, 3.7vw, 1.05rem);
        line-height: 1.55;
        background: rgba(255, 255, 255, 0.8);
        -webkit-backdrop-filter: blur(10px);
        backdrop-filter: blur(10px);
    }

    .historia-layer {
        left: var(--layer-x-m, var(--layer-x, 50%));
        top: var(--layer-y-m, var(--layer-y, 70%));
        width: calc(var(--layer-w-m, 60) * 1vw);
    }

    .historia-layer--hide-mobile {
        display: none;
    }

    .historia-layer img {
        max-height: 70vh;
    }

    .historia-text-row {
        grid-template-columns: 1fr;
        gap: 0.65rem;
    }
}

@media (max-width: 767px) {
    .historia-view-toggle {
        left: 0.75rem;
        bottom: 0.75rem;
    }
}

