/* Photo pins of the full memory map (exp_memory_map_clusters, docs/MEMORY_MAP_LAYER.md).
   The clusters, dots and glow are WebGL layers coloured from the same tokens in
   memory-map-layer.js; only these pins are DOM. Tokens only (design-system/AI_RULES.md).

   A pin is a rounded photo frame over a tail, both in the brand colour of the dots.
   The marker is anchored at its bottom edge and the tail ends there, so the tip sits
   on the place and runs into its dot or cluster: one shape, frame to point. */

/* MapLibre owns this element's transform (its position); never animate it. */
.mb-memory-marker {
    --mb-memory-pin-tail: var(--ds-space-2);
    padding-bottom: var(--mb-memory-pin-tail);
    line-height: 0;
}

.mb-memory-marker:hover,
.mb-memory-marker:focus-within {
    z-index: 2;
}

.mb-memory-bubble {
    --mb-memory-bubble-size: 44px;
    position: relative;
    display: block;
    width: var(--mb-memory-bubble-size);
    height: var(--mb-memory-bubble-size);
    padding: 0;
    border: 3px solid var(--ds-brand);
    border-radius: var(--ds-radius-md);
    background: var(--ds-brand-tint);
    /* A light ring separates the frame from the map, as the dots' stroke does. */
    box-shadow: 0 0 0 2px var(--ds-card), var(--ds-shadow-elevated);
    font-family: var(--ds-font-sans);
    cursor: pointer;
    /* Grow and shrink around the tip, so the place under it never moves. */
    transform-origin: 50% calc(100% + var(--mb-memory-pin-tail));
    transition: transform 160ms ease-out, box-shadow 160ms ease-out;
}

/* The tail: a triangle in the frame's colour, from the frame's bottom edge to the tip. */
.mb-memory-bubble::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: calc(-1 * (var(--mb-memory-pin-tail) + 3px));
    width: 0;
    height: 0;
    border-top: var(--mb-memory-pin-tail) solid var(--ds-brand);
    border-right: var(--mb-memory-pin-tail) solid transparent;
    border-left: var(--mb-memory-pin-tail) solid transparent;
    transform: translateX(-50%);
}

/* Several memories: a second card peeks out behind the photo. */
.mb-memory-bubble--group {
    box-shadow:
        0 0 0 2px var(--ds-card),
        var(--ds-space-1) calc(-1 * var(--ds-space-1)) 0 0 var(--ds-brand-tint),
        var(--ds-space-1) calc(-1 * var(--ds-space-1)) 0 2px var(--ds-card),
        var(--ds-shadow-elevated);
}

.mb-memory-bubble:hover {
    transform: scale(1.08);
}

.mb-memory-bubble:focus-visible {
    outline: 3px solid var(--ds-focus);
    outline-offset: 2px;
}

.mb-memory-bubble__photo {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: calc(var(--ds-radius-md) - 3px);
    object-fit: cover;
}

/* No photo, or a photo that failed to load: the tinted frame shows a picture glyph,
   never a broken image. The glyph is a mask, coloured by the token. */
.mb-memory-bubble--no-photo .mb-memory-bubble__photo {
    visibility: hidden;
}

.mb-memory-bubble--no-photo::before {
    content: "";
    position: absolute;
    inset: 22%;
    background-color: var(--ds-brand-strong);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 4h16a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2zm0 2v9.6l4.3-4.3a1 1 0 0 1 1.4 0l3.3 3.3 2.3-2.3a1 1 0 0 1 1.4 0L20 15.6V6H4zm11.5 1.5a2 2 0 1 1 0 4 2 2 0 0 1 0-4z'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 4h16a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2zm0 2v9.6l4.3-4.3a1 1 0 0 1 1.4 0l3.3 3.3 2.3-2.3a1 1 0 0 1 1.4 0L20 15.6V6H4zm11.5 1.5a2 2 0 1 1 0 4 2 2 0 0 1 0-4z'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* Dark label on the brand fill: white on #EA794C is below AA (AI_RULES.md §6). */
.mb-memory-bubble__count {
    position: absolute;
    top: calc(-1 * var(--ds-space-2));
    right: calc(-1 * var(--ds-space-3));
    min-width: 24px;
    padding: 2px 6px;
    border: 2px solid var(--ds-card);
    border-radius: var(--ds-radius-pill);
    background: var(--ds-brand);
    color: var(--ds-ink);
    font-size: 11px;
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
    box-shadow: var(--ds-shadow-card);
}

.mb-memory-bubble__count[hidden],
.mb-memory-bubble__title[hidden] {
    display: none;
}

/* What the pin shows, on hover and keyboard focus. One line; the button's accessible
   name carries the whole title. */
.mb-memory-bubble__title {
    position: absolute;
    bottom: calc(100% + var(--ds-space-2));
    left: 50%;
    max-width: 220px;
    padding: var(--ds-space-1) var(--ds-space-2);
    overflow: hidden;
    border-radius: var(--ds-radius-pill);
    background: var(--ds-card);
    box-shadow: var(--ds-shadow-card);
    color: var(--ds-ink);
    font-size: var(--ds-font-size-caption);
    font-weight: 600;
    line-height: var(--ds-line-height-caption);
    text-overflow: ellipsis;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transform: translateX(-50%);
    transition: opacity 120ms ease-out;
}

.mb-memory-bubble:hover .mb-memory-bubble__title,
.mb-memory-bubble:focus-visible .mb-memory-bubble__title {
    opacity: 1;
}

.mb-memory-bubble--enter {
    animation: mb-memory-bubble-in 220ms ease-out;
}

@keyframes mb-memory-bubble-in {
    from { opacity: 0; transform: translateY(var(--ds-space-2)) scale(0.6); }
    to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .mb-memory-bubble,
    .mb-memory-bubble--enter,
    .mb-memory-bubble__title {
        animation: none;
        transition: none;
    }

    .mb-memory-bubble:hover {
        transform: none;
    }
}
