/* Memory Slots - save slots and animations */

#memoryControls {
    position: relative;
    z-index: 1;
    margin-top: 2px;
    margin-bottom: 2em;
    padding: 0px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    min-height: 42px;
}

body.string-generator #memoryControls {
    margin-bottom: 0em;
}

#memoryControls > * {
    flex: 0 0 auto;
}

.memoryLabel {
    margin-bottom: 1.5px;
    font-weight: 800;
    font-size: 16px;
    text-align: center;
    background: linear-gradient(135deg, var(--panel-muted), var(--panel-bg));
    color: var(--text-primary);
    padding: 9px 16px;
    border-radius: 14px;
    box-shadow: 0 12px 28px var(--shadow-strong);
    border: 1.5px solid rgba(255, 255, 255, 0.08);
    letter-spacing: 0.2px;
}

.memoryLabel:hover {
    background: linear-gradient(135deg, #0f2b1c, #0c2318);
    border-color: rgba(34, 201, 119, 0.85);
    box-shadow:
        0 0 0 2px rgba(34, 201, 119, 0.2),
        0 10px 20px rgba(34, 201, 119, 0.25),
        0 14px 30px var(--shadow-strong);
    color: #e7f4ff;
}

.memoryLabel.active {
    background: linear-gradient(135deg, #1c5c3c, #177746);
    border-color: rgba(34, 201, 119, 0.9);
    box-shadow:
        0 0 0 2px rgba(34, 201, 119, 0.3),
        0 12px 24px rgba(34, 201, 119, 0.32);
    color: #f8fbff;
}

@media (max-width: 768px) {
    .memoryLabel {
        font-size: 22px;
        padding: 6px 10px;
        margin-bottom: -2px;
    }
    .memory-text {
        display: none;
    }
}

.memoryButtons {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    align-items: flex-end;
    max-width: 100%;
    padding: 0 5px;
}

/* Memory slot container with relative positioning for the clear button */
.memorySlotContainer {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    transition: all 0.3s ease;
    margin-top: 20px; /* Reduced space for clear button above */
    background: transparent; /* Ensure no background color inheritance */
    flex: 0 0 auto;
}

.memorySlotContainer:hover {
    /* Removed lifting effect */
}

.memorySlotContainer.active {
    /* Active state handled by memory slot itself */
}

/* Music notes animation for currently playing */
.memorySlotContainer.playing {
    position: relative;
}

.memorySlotContainer.playing::after {
    content: '♪ ♫';
    position: absolute;
   top: 20px;
   left: 20px;
   transform: translate(-50%, -50%);
    font-size: 8px;
    color: #3498db;
    opacity: 0;
    pointer-events: none;
    animation: musicNotesFloat 1.5s ease-in-out infinite;
   z-index: 2;
}

@keyframes musicNotesFloat {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5) rotate(0deg);
    }
    25% {
        opacity: 1;
        transform: translate(-65%, -65%) scale(0.8) rotate(10deg);
    }
    50% {
        opacity: 0.8;
        transform: translate(-80%, -80%) scale(1) rotate(20deg);
    }
    75% {
        opacity: 0.4;
        transform: translate(-95%, -95%) scale(1.2) rotate(30deg);
    }
    100% {
        opacity: 0;
        transform: translate(-110%, -110%) scale(1.5) rotate(40deg);
    }
}

.memorySlot {
    width: 36px;
    height: 36px;
    padding: 0;
    font-size: 14px;
    font-weight: bold;
    border-radius: 50%;
    background-color: #7f8c8d;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: all 0.3s ease;
    border: 3px solid transparent;
    color: white;
    z-index: 2;
}

.memorySlot:hover {
    background-color: #95a5a6;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    border-color: rgba(34, 201, 119, 0.35);
}

.memorySlot.saved {
    background-color: #27ae60;
    box-shadow: 0 2px 8px rgba(39, 174, 96, 0.3);
    border-color: rgba(255, 255, 255, 0.18);
}

.memorySlot.saved:hover {
    background-color: #2ecc71;
    box-shadow: 0 4px 12px rgba(39, 174, 96, 0.4);
    /* Removed transform to prevent jiggle */
}

.memorySlot.active {
    background-color: #27ae60;
    color: white;
    border-color: #3498db;
    box-shadow: 0 0 12px rgba(52, 152, 219, 0.8);
    animation: activeBorderPulse 2s ease-in-out infinite;
}

@keyframes activeBorderPulse {
    0%, 100% {
        box-shadow: 0 0 10px rgba(34, 201, 119, 0.6);
        border-color: rgba(34, 201, 119, 0.9);
    }
    50% {
        box-shadow: 0 0 16px rgba(34, 201, 119, 0.8);
        border-color: rgba(34, 201, 119, 0.6);
    }
}

.memorySlot.queued {
    background-color: #27ae60;
    color: white;
    border-color: #f39c12;
    box-shadow: 0 0 8px rgba(243, 156, 18, 0.6);
    animation: queuedBorderPulse 2s ease-in-out infinite;
}

@keyframes queuedBorderPulse {
    0%, 100% {
        box-shadow: 0 0 4px rgba(243, 156, 18, 0.4);
        border-color: #f39c12;
    }
    50% {
        box-shadow: 0 0 8px rgba(243, 156, 18, 0.7);
        border-color: #e67e22;
    }
}

/* Clear button styling - positioned below the memory slot */
.memorySlotClear {
    position: absolute;
    top: -22px; /* Position further above the memory slot */
    left: 50%; /* Center horizontally without rightward offset */
    transform: translateX(-50%);
    width: 10px;
    height: 10px;
    min-width: 10px;
    min-height: 10px;
    padding: 7px;
    flex: 0 0 auto;
    margin: 0;
    font-size: 12px;
    font-weight: bold;
    line-height: 1;
    letter-spacing: -0.5px;
    border-radius: 50%;
    background-color: #e74c3c;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    border: 1px solid white;
    box-sizing: border-box;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    text-shadow: 1px 1px 0px black;
    display: inherit !important;
    z-index: 10;
    flex-shrink: 0;
}

.memorySlotClear:hover {
    background-color: #c0392b;
    transform: translateX(-50%) scale(1.05);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4);
}

.memorySlotContainer:hover .memorySlotClear {
    opacity: 1;
    pointer-events: auto;
}

.memorySlotContainer.has-memory .memorySlotClear {
    opacity: 0.7;
    pointer-events: auto;
}

.memorySlotContainer.has-memory:hover .memorySlotClear {
    opacity: 1;
}

.memory-slot-placeholder {
    background: linear-gradient(135deg, #e3f2fd 25%, transparent 25%, transparent 50%, #e3f2fd 50%, #e3f2fd 75%, transparent 75%, transparent);
    background-size: 20px 20px;
    border: 2px dashed #2196F3;
    border-radius: 8px;
    opacity: 0.7;
}

.memory-slot-placeholder .memorySlot,
.memory-slot-placeholder .memorySlotClear {
    visibility: hidden;
}

#addMemorySlot, #printMemorySlotsBtn {
    width: 36px;
    height: 36px;
    margin-top: 20px;
    padding: 0;
    font-size: 16px;
    font-weight: 800;
    border-radius: 12px;
    color: #f8fbff;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    border: 1.5px solid rgba(255, 255, 255, 0.12);
}

#addMemorySlot {
    background: linear-gradient(145deg, #2bb673, #20a864);
    box-shadow: 0 12px 24px rgba(32, 168, 100, 0.35);
    border-radius: 50%;
}

#addMemorySlot:hover {
    background: linear-gradient(145deg, #33d285, #24b673);
    border-color: rgba(34, 201, 119, 0.8);
    box-shadow: 0 18px 32px rgba(34, 201, 119, 0.4);
    transform: translateY(-1px);
}

#printMemorySlotsBtn {
    background: linear-gradient(145deg, #1b86d6, #166fb3);
    box-shadow: 0 12px 24px rgba(27, 134, 214, 0.35);
    border: 1.5px solid rgba(255, 255, 255, 0.18);
    position: relative;
}

#printMemorySlotsBtn:hover {
    background: linear-gradient(145deg, #229cf2, #1b86d6);
    border-color: rgba(34, 201, 119, 0.9);
    border-width: 3px;
    box-shadow:
        0 0 0 3px rgba(34, 201, 119, 0.35),
        0 18px 32px rgba(34, 201, 119, 0.35),
        0 12px 24px rgba(27, 134, 214, 0.45);
    transform: translateY(-1px);
}

#printMemorySlotsBtn::after {
    content: 'Print (Cmd+P)';
    position: absolute;
    bottom: 115%;
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    background: rgba(15, 32, 56, 0.95);
    color: #e7f4ff;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.12);
    z-index: 20;
}

#printMemorySlotsBtn:hover::after,
#printMemorySlotsBtn:focus-visible::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
