* {
    margin: 0;
}

body {
    background-color: rgb(0,0,0);
    font-family: Verdana, Geneva, Tahoma, sans-serif;
}

/*
   anim-w/tile-w ≈ 5.1 and anim-h/tile-h ≈ 5.1
   so that the tile expand scale(5) visually fills the animation. */
:root {
    --v-anim-w: 930px;       /* animation inner width  */
    --v-anim-h: 714px;       /* animation inner height (930/770 × 591) */
    --v-tile-w: 182px;       /* tile width  (930/770 × 151) */
    --v-tile-h: 139px;       /* tile height (930/770 × 115) */
    --v-tile-scale: 5;       /* expand scale — keep in sync with ratios above */
    --v-gap: 4px;            /* gap between animation right edge and tile column */
    --v-tracks-w: 160px;     /* tile column width */
    --v-expand-scale: 5.1;   /* anim-w / tile-w — used to fake full size via transform */
    --v-shrink-scale: 0.196; /* tile-w / anim-w — used to fake tile size via transform */
}

@media (max-width: 1150px) {
    :root {
        --v-anim-w: 820px;  /* 820/151 × ratio preserved */
        --v-anim-h: 630px;
        --v-tile-w: 161px;
        --v-tile-h: 123px;
    }
}

@media (max-width: 1000px) {
    :root {
        --v-anim-w: 700px;
        --v-anim-h: 537px;
        --v-tile-w: 137px;
        --v-tile-h: 105px;
    }
}



.interactive-map {
    position: fixed;
    bottom: var(--step-0);
    left: calc(max(var(--step--2), calc((100vw - var(--max-width)) / 2)) + calc(var(--step-0) * 2) + var(--step--2));
    width: calc(var(--v-anim-w) + 2px + var(--v-gap) + var(--v-tracks-w));
    height: var(--v-anim-h);
}

.map {
    position: relative; /* needed for .animation-border absolute positioning */
    display: flex;
    flex-direction: column;
    gap: 3px;
    height: var(--v-anim-h);

    .track-info {
        display: none;
        width: var(--v-tile-w);
        height: var(--v-tile-h);
        margin: 0;
        color: var(--color-yellow);
        font-size: 12px;
        overflow: hidden;
        border: 1px solid var(--color-red);
        flex-direction: column;
        justify-content: space-evenly;
    }

    .track-data {
        display: none;
        width: var(--v-tile-w);
        flex: 1;
        height: auto;
        padding: 0;
        margin-top: 0;
        color: var(--color-yellow);
        font-size: 10px;
        overflow: hidden;
        overflow-y: scroll;
        scrollbar-width: none; /* Firefox */
        border: 1px solid var(--color-red);
    }

    .track-data::-webkit-scrollbar {
        display: none; /* Chrome, Safari */
    }

    &.is-shrunk .track-info,
    &.is-shrunk .track-data {
        display: flex;
        /* fade in near the end of the 1s shrink animation so they don't
           appear while the animation still visually fills the space */
        animation: v-fade-in 0.3s ease 0.7s backwards;
    }
}

.animation-border {
    position: absolute;
    top: 0;
    left: 0;
    width: var(--v-anim-w);
    height: var(--v-anim-h);
    border: 1px solid var(--color-red);
    pointer-events: none;
    z-index: 2;
    box-sizing: border-box;
    transition: width 1s ease, height 1s ease;
}

.map.is-shrunk .animation-border {
    width: var(--v-tile-w);
    height: var(--v-tile-h);
}

.animation {
    position: relative;
    display: inline-block;
    background-color: black;
    width: var(--v-anim-w);
    height: var(--v-anim-h);
    overflow: hidden;
    transform-origin: top left;
    will-change: transform;
    pointer-events: none;
    cursor: default;

    .video {
        width: 100%;
        height: 100%;
        object-fit: cover;
        outline: none;
        outline-offset: 0;
        max-width: none;
    }

    .draghandle {
        position: absolute;
        background-color: var(--color-red);
        width: 4px;
        height: 10px;
        cursor: pointer;
        touch-action: none;
        visibility: hidden;
        bottom: 0;
        pointer-events: auto;
        transition: opacity 0s 1s; /* appear after 1s (once expand is done) */
    }

    .arrow {
        position: absolute;
        width: 15px;
        bottom: 2px;
        right: 2px;
        opacity: 0;
        transform: rotate(180deg);
        transition: opacity 0s; /* hide immediately, no delay */
    }

    &.shrunk {
        width: var(--v-tile-w);
        height: var(--v-tile-h);
        pointer-events: auto;
        cursor: pointer;
    }

    /* GPU-composited keyframe animations replace width/height transitions */
    &.shrinking {
        animation: v-anim-shrink 1s ease forwards;
    }

    &.expanding {
        animation: v-anim-expand 1s ease forwards;
    }

    &.shrunk .draghandle {
        opacity: 0;
        transition: opacity 0s; /* hide immediately, no delay */
    }

    &.shrunk .arrow {
        opacity: 1;
        transition: opacity 0s 1s; /* appear after 1s (once expand is done) */
    }
}

.label {
    font-size: 10px;
    color: #cccccc;
    margin-top: 4px;
    margin-left: 2px;
}

.value {
    margin-left: 2px;
}

.tracks {
    position: absolute;
    left: calc(var(--v-anim-w) + 2px + var(--v-gap));
    top: 0;
    height: 100%;
    width: var(--v-tracks-w);
}

.tile-frame {
    /* outer wrapper: handles positioning and border */
    position: absolute;
    width: var(--v-tile-w);
    height: var(--v-tile-h);
    padding: 0;
    margin: 0;
    overflow: visible;
    z-index: 10;
    background-color: black;

    &::after {
        /* border drawn here so it is never scaled */
        content: '';
        position: absolute;
        right: 0;
        bottom: 0;
        width: var(--v-tile-w);
        height: var(--v-tile-h);
        border: 1px solid var(--color-red);
        box-sizing: border-box;
        pointer-events: none;
        z-index: 20; /* always above the inner .tile */
        transition: width 1s ease, height 1s ease;
    }

    &.expanded {
        z-index: 100;
        top: calc(var(--v-anim-h) - var(--v-tile-h)) !important;
    }

    &.transitioning {
        z-index: 100;
    }

    &.expanded::after {
        /* match the visual size of the expanded tile */
        width: calc(var(--v-anim-w) + 2px);
        height: var(--v-anim-h);
    }
}

.tile {
    width: var(--v-tile-w);
    height: var(--v-tile-h);
    padding: 0;
    margin: 0;
    color: var(--color-yellow);
    font-size: 12px;
    overflow: hidden;
    cursor: pointer;
    transform-origin: right bottom;
    will-change: transform;
    transition: transform 1s ease;

    &.tile.expanded {
        transform: scale(var(--v-tile-scale));
        cursor: default;
    }
    .overlay {
        position: absolute;
        padding: 2px;
        z-index: 10;
    }
    .caption {
        color: var(--color-yellow);
        padding-left: 2px;
    }
    .arrow {
        display: inline;
        width: 15px;
    }
    .video {
        position: absolute;
        width: var(--v-tile-w);
        z-index: 5;
        outline: none;
        outline-offset: 0;
        max-width: none;
    }
}

/* === Keyframe animations for the main animation shrink/expand ===
   The element snaps to its target layout size instantly (one reflow),
   while the transform provides a smooth GPU-composited visual transition.

   Shrink: layout snaps to tile size, transform fakes full size → animates to 1
   Expand: layout snaps to full size, transform fakes tile size → animates to 1  */

/* Disable size transitions during browser resize so breakpoint changes snap instantly */
.is-resizing .animation-border,
.is-resizing .tile-frame::after {
    transition: none !important;
}

@keyframes v-anim-shrink {
    from { transform: scale(var(--v-expand-scale)); }
    to   { transform: scale(1); }
}

@keyframes v-anim-expand {
    from { transform: scale(var(--v-shrink-scale)); }
    to   { transform: scale(1); }
}

@keyframes v-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
