/* ===========================================================================
   Recently used Algorithms / Trainers / Tools.

   Home cards show up to three icon-only shortcuts; the desktop header shows
   the same shortcuts in a small overlay dropdown on hover. The data lives in
   localStorage (see js/recentItems.js) — there is no server-side tracking.

   The links are deliberately icon-only: the label is only used for the
   tooltip/accessible name.
   =========================================================================== */

.recent-items {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    margin-top: 0.9rem;
    position: relative;
    /* Above the stretched link that makes the rest of a home card clickable. */
    z-index: 2;
    /* Only the icons should take clicks; the empty part of the row still
       belongs to the card link underneath. */
    pointer-events: none;
}

.recent-items .recent-item {
    pointer-events: auto;
}

.recent-items[hidden],
.recent-dropdown[hidden] {
    display: none !important;
}

.recent-item {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    text-decoration: none;
    color: var(--accent-color);
    background: rgba(var(--accent-color-rgb), 0.09);
    border: 1px solid rgba(var(--accent-color-rgb), 0.22);
    border-radius: 10px;
    transition: background-color 0.14s ease, border-color 0.14s ease, transform 0.14s ease;
}

.recent-item:hover,
.recent-item:focus-visible {
    background: rgba(var(--accent-color-rgb), 0.18);
    border-color: rgba(var(--accent-color-rgb), 0.45);
    color: var(--accent-color);
    transform: translateY(-1px);
    outline: none;
}

.recent-items .recent-item {
    width: 36px;
    height: 36px;
}

.recent-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    line-height: 1;
    pointer-events: none;
}

.recent-icon img {
    width: 24px;
    height: 24px;
    object-fit: contain;
    display: block;
}

.recent-icon i,
.recent-icon .cubing-icon {
    font-size: 1.15rem;
    line-height: 1;
}

/* ── Desktop header hover dropdown ─────────────────────────────────────── */

.header-nav-item {
    position: relative;
    display: flex;
    align-items: center;
}

.recent-dropdown {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.3rem;
    padding: 0.35rem;
    background: rgba(33, 37, 41, 0.86);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.24);
    backdrop-filter: blur(6px);
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.16s ease, visibility 0s linear 0.16s;
}

.recent-dropdown.is-open {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.12s ease, visibility 0s linear 0s;
}

/* Invisible bridge over the gap between the nav icon and the menu, so the
   pointer can cross it without leaving the hover area. */
.recent-dropdown::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 0;
    right: 0;
    height: 8px;
}

.recent-dropdown .recent-item {
    width: 42px;
    height: 42px;
    background: transparent;
    border: 0;
    border-radius: 8px;
    box-shadow: none;
}

.recent-dropdown .recent-item:hover,
.recent-dropdown .recent-item:focus-visible {
    background: rgba(255, 255, 255, 0.1);
    border: 0;
    box-shadow: none;
}

.recent-dropdown .recent-item:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: -2px;
}

.recent-dropdown .recent-icon img {
    width: 28px;
    height: 28px;
}

.recent-dropdown .recent-icon i,
.recent-dropdown .recent-icon .cubing-icon {
    font-size: 1.3rem;
}

/* The normal hover tooltip would overlap the dropdown; hide it while the
   recent menu is open. */
.header-nav-item.recent-open .header-nav-label {
    opacity: 0 !important;
    visibility: hidden !important;
}

@media (max-width: 767.98px), (hover: none), (pointer: coarse) {
    .recent-dropdown {
        display: none !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    .recent-item,
    .recent-dropdown {
        transition: none;
    }
}
