/* The map of the Gulf in the home hero (includes/gulf_map.html). In 3D (main/static/js/gulf-map/)
   the Gulf states rise into a platform with the Kanidata emblem on Dubai and links out across
   the region. Without WebGL or with reduced motion, the SVG version below builds itself the
   same way (borders, fill, Dubai's pin, then the links). The point glow afterwards only runs
   while the map is on screen (gulf-map.js toggles .is-live). */
.gm {
    --gm-ease: cubic-bezier(0.22, 1, 0.36, 1);
}

/* ---------- The map ---------- */
/* A 4:3 frame keeps the hero compact (the tilted 3D map needs less height than the flat
   map). The map fades out in an oval that reaches nothing by the frame's edges, so the map
   melts into the hero instead of stopping at a straight line. */
.gm__frame {
    position: relative;
    aspect-ratio: 4 / 3;
    overflow: hidden; /* or the map's own shape would stretch the frame past 4:3 */
    -webkit-mask-image: radial-gradient(50% 50% at 50% 50%, #000 86%, transparent 100%);
    mask-image: radial-gradient(50% 50% at 50% 50%, #000 86%, transparent 100%);
}

/* The country borders (includes/gulf-map.svg), one path per country, fitted inside the frame
   the same way as the layer of links and points over it. */
.gm-land {
    display: block;
    width: 100%;
    height: 100%;
}

.gm-land path {
    stroke-linejoin: round;
}

.gm-land__near path {
    fill: none;
    stroke: var(--kd-line-strong);
    stroke-width: 1;
}

.gm-land__gcc path {
    fill: var(--kd-brand-soft);
    stroke: #8FA6D6;
    stroke-width: 1.2;
}

/* With a mouse the map leans towards the pointer (gulf-map.js sets --rx and --ry). The two
   layers share one box, so they tilt as one; the wrapper's own transform is the reveal. */
.gm__frame > .gm-land,
.gm__frame > .gm-svg {
    transform: perspective(1100px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg));
    transition: transform 0.6s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.8s ease;
}

/* The flat map waits unseen while the 3D map loads, and shows only if gulf-map.js decides it
   is needed (.is-flat). Hidden from the first paint, so it never flashes up before the
   scripts run; without JavaScript a <noscript> style in gulf_map.html shows it. */
.gm:not(.is-flat) .gm__frame > .gm-land,
.gm:not(.is-flat) .gm__frame > .gm-svg {
    opacity: 0;
}

.gm-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
}

.gm-svg__arcs path {
    fill: none;
    stroke: #FFFFFF;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-opacity: 0.75;
}

.gm-svg__points circle,
.gm-svg__pop {
    transform-box: fill-box;
    transform-origin: center;
}

.gm-svg__points circle {
    fill: var(--kd-mint);
    stroke: #FFFFFF;
    stroke-width: 2;
}

.gm-svg__dot {
    fill: var(--kd-brand-darkest);
    stroke: #FFFFFF;
    stroke-width: 3;
}

.gm-svg__label rect {
    fill: var(--kd-brand-deep);
}

.gm-svg__label text {
    fill: #FFFFFF;
    font-size: 12px;
    font-weight: 600;
}

/* ---------- The 3D map (main/static/js/gulf-map/) ---------- */
/* Holds the map and, outside its mask, the 3D map's labels. */
.gm {
    position: relative;
}

/* Once the 3D map draws its first frame it adds .has-3d: the canvas fades in as the flat map
   fades out, which stays in place (unseen) only to give the map its size. */
.gm__canvas {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.8s ease;
}

.gm__frame.has-3d .gm__canvas {
    opacity: 1;
}

.gm__frame.has-3d > .gm-land,
.gm__frame.has-3d > .gm-svg {
    opacity: 0;
}

.gm__label {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    padding: 0.2rem 0.65rem;
    border-radius: 999px;
    background: var(--kd-brand-deep);
    color: #FFFFFF;
    font-size: 0.75rem;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.gm__label.is-shown {
    opacity: 1;
}

/* A point's name, shown above its marker while it is hovered or tapped. */
.gm__city {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    background: #FFFFFF;
    box-shadow: 0 0 0 1px var(--kd-line), 0 8px 20px -10px rgba(15, 23, 42, 0.35);
    color: var(--kd-ink);
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.gm__city.is-shown {
    opacity: 1;
}

/* ---------- Motion (with JavaScript) ---------- */
.gm.is-js .gm__frame {
    opacity: 0;
    transform: translateY(28px);
    transition: opacity 0.9s var(--gm-ease), transform 0.9s var(--gm-ease);
}

.gm.is-js .gm__frame.is-in {
    opacity: 1;
    transform: none;
}

/* The map builds itself in order: the neighbouring borders trace in, then the Gulf
   states, their fill washes in, Dubai is pinned, and the links draw out to each point.
   It plays once, when the flat map is in use (.is-flat) and the hero has opened (.is-in). */
.gm.is-js .gm-land path,
.gm.is-js .gm-svg__arcs path {
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
}

.gm.is-js .gm-land__near path {
    transition: stroke-dashoffset 1s var(--gm-ease) calc(var(--i) * 0.04s);
}

.gm.is-js .gm-land__gcc path {
    fill-opacity: 0;
    transition:
        stroke-dashoffset 1.2s var(--gm-ease) calc(0.2s + var(--i) * 0.08s),
        fill-opacity 0.6s ease 0.9s;
}

.gm.is-js .gm-svg__pop {
    transform: scale(0);
    transition: transform 0.5s cubic-bezier(0.34, 1.6, 0.6, 1) 1.1s;
}

.gm.is-js .gm-svg__arcs path {
    transition: stroke-dashoffset 0.9s var(--gm-ease) calc(1.2s + var(--i) * 0.1s);
}

.gm.is-js .gm-svg__points circle {
    transform: scale(0);
    transition: transform 0.5s cubic-bezier(0.34, 1.6, 0.6, 1) calc(1.8s + var(--i) * 0.1s);
}

.gm.is-flat .gm__frame.is-in .gm-land path,
.gm.is-flat .gm__frame.is-in .gm-svg__arcs path {
    stroke-dashoffset: 0;
}

.gm.is-flat .gm__frame.is-in .gm-land__gcc path {
    fill-opacity: 1;
}

.gm.is-flat .gm__frame.is-in .gm-svg__pop,
.gm.is-flat .gm__frame.is-in .gm-svg__points circle {
    transform: none;
}

/* While on screen, the points glow in turn. */
.gm-svg__points circle {
    animation: gm-point-glow 4.8s ease-in-out infinite;
    animation-delay: calc(2.4s + var(--i) * 0.8s);
    animation-play-state: paused;
}

.gm.is-live .gm-svg__points circle {
    animation-play-state: running;
}

@keyframes gm-point-glow {
    0%,
    24%,
    100% {
        fill: var(--kd-mint);
    }

    10% {
        fill: var(--kd-brand);
    }
}

@media (prefers-reduced-motion: reduce) {
    .gm-svg__points circle {
        animation: none;
    }

    .gm__frame > .gm-land,
    .gm__frame > .gm-svg {
        transform: none;
        transition: none;
    }

    .gm.is-js .gm__frame {
        opacity: 1;
        transform: none;
        transition: none;
    }

    .gm.is-js .gm-land path,
    .gm.is-js .gm-svg__arcs path,
    .gm.is-js .gm-svg__pop,
    .gm.is-js .gm-svg__points circle {
        stroke-dashoffset: 0;
        fill-opacity: 1;
        transform: none;
        transition: none;
    }
}
