const detailsElements = document.getElementsByTagName('details');

const save = () => {
    Array.from(detailsElements).forEach((details, i) => {
        localStorage.setItem(`details${i}`, details.hasAttribute('open'));
    });
};

Array.from(detailsElements).forEach((details, i) => {
    const isOpen = JSON.parse(localStorage.getItem(`details${i}`)) || false;
    details.toggleAttribute('open', isOpen);
    details.addEventListener('toggle', save);

    const svg = details.querySelector('summary svg');
    if (svg) {
        svg.style.transition = isOpen ? 'none' : '';
    }
});

setTimeout(() => {
    Array.from(detailsElements).forEach(details => {
        const svg = details.querySelector('summary svg');
        if (svg) svg.style.transition = '';
    });
}, 100);