/* ========================================
   SETTINGS MENU - ENHANCED MODERN DESIGN
   ======================================== */

/* Wrapper - positioned relative to toggle buttons */
.settings-button-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
    margin-left: 12px;
    z-index: 1000;
}

/* Ensure parent containers don't clip the dropdown menu */
.settings-button-wrapper,
.header-controls-wrapper,
.spell-list-toggle-wrapper {
    overflow: visible !important;
}

/* Settings Button - Modern glassmorphic design */
.settings-icon-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    background: rgba(167, 139, 250, 0.08);
    border: 1.5px solid rgba(167, 139, 250, 0.25);
    border-radius: 12px;
    color: #a78bfa;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    backdrop-filter: blur(8px);
}

.settings-icon-btn:hover {
    background: rgba(167, 139, 250, 0.15);
    border-color: rgba(167, 139, 250, 0.5);
    box-shadow: 0 8px 24px rgba(167, 139, 250, 0.2);
    transform: translateY(-1px) rotate(90deg);
}

.settings-icon-btn.active {
    background: rgba(167, 139, 250, 0.2);
    border-color: rgba(167, 139, 250, 0.6);
    box-shadow: 0 0 0 4px rgba(167, 139, 250, 0.1);
}

.settings-icon-btn svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Settings Menu - Premium dropdown design */
.settings-menu {
    position: fixed;
    top: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    background: linear-gradient(135deg, rgba(15, 15, 25, 0.98), rgba(20, 20, 35, 0.98));
    backdrop-filter: blur(40px) saturate(180%);
    -webkit-backdrop-filter: blur(40px) saturate(180%);
    border: 1px solid rgba(167, 139, 250, 0.15);
    border-radius: 16px;
    padding: 8px;
    min-width: 340px;
    max-width: 380px;
    box-shadow: 
        0 24px 48px rgba(0, 0, 0, 0.6),
        0 0 0 1px rgba(167, 139, 250, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
    overflow: visible;
    
    /* Hidden by default */
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-12px) scale(0.95);
    transform-origin: top right;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 10000;
}

.settings-menu.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

/* Menu Header */
.settings-menu-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    background: linear-gradient(135deg, rgba(167, 139, 250, 0.08), rgba(167, 139, 250, 0.04));
    border-bottom: 1px solid rgba(167, 139, 250, 0.15);
    border-radius: 12px 12px 0 0;
    margin: -8px -8px 8px -8px;
}

.settings-menu-header svg {
    width: 22px;
    height: 22px;
    stroke: #a78bfa;
    stroke-width: 2;
    fill: none;
    flex-shrink: 0;
}

.settings-menu-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: #a78bfa;
    font-family: 'Lora', serif;
}

/* Menu Sections */
.settings-menu-section {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 0;
}

.settings-menu-section + .settings-menu-section {
    border-top: 1px solid rgba(255, 255, 255, 0.04);
    margin-top: 8px;
    padding-top: 8px;
}

.settings-menu-section-title {
    padding: 8px 12px 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #9ca3af;
    font-family: 'Lora', serif;
}

/* Menu Items */
.settings-menu-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 10px;
    user-select: none;
    color: #d1d5db;
    font-size: 0.9rem;
    font-weight: 500;
    font-family: 'Lora', serif;
    position: relative;
    overflow: hidden;
}

.settings-menu-item::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(167, 139, 250, 0.08), rgba(123, 201, 166, 0.08));
    opacity: 0;
    transition: opacity 0.2s ease;
    border-radius: 10px;
}

.settings-menu-item:hover::before {
    opacity: 1;
}

.settings-menu-item:hover {
    color: #a78bfa;
    transform: translateX(2px);
}

.settings-menu-item:active {
    transform: translateX(2px) scale(0.98);
}

.settings-menu-item svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.settings-menu-item-text {
    flex: 1;
    position: relative;
    z-index: 1;
}

.settings-menu-item-text small {
    display: block;
    font-size: 0.75rem;
    color: #9ca3af;
    margin-top: 2px;
    font-weight: 400;
}

/* Special item styles */
.settings-menu-item[data-action="download"] {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.05), rgba(34, 197, 94, 0.02));
}

.settings-menu-item[data-action="download"]:hover {
    color: #4ade80;
}

.settings-menu-item[data-action="upload"] {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.05), rgba(59, 130, 246, 0.02));
}

.settings-menu-item[data-action="upload"]:hover {
    color: #60a5fa;
}

/* Legal Notice */
.settings-menu-legal {
    padding: 12px 14px;
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.08), rgba(245, 158, 11, 0.04));
    border: 1px solid rgba(245, 158, 11, 0.2);
    border-radius: 10px;
    margin-top: 8px;
}

.settings-menu-legal p {
    margin: 0;
    font-size: 0.75rem;
    line-height: 1.5;
    color: #fbbf24;
    font-family: 'Lora', serif;
}

.settings-menu-legal strong {
    color: #fcd34d;
    font-weight: 600;
}

/* Pro Tip */
.settings-menu-tip {
    padding: 12px 14px;
    background: linear-gradient(135deg, rgba(167, 139, 250, 0.08), rgba(123, 201, 166, 0.08));
    border: 1px solid rgba(167, 139, 250, 0.15);
    border-radius: 10px;
    margin-top: 8px;
}

.settings-menu-tip p {
    margin: 0;
    font-size: 0.75rem;
    line-height: 1.5;
    color: #c4b5fd;
    font-family: 'Lora', serif;
}

.settings-menu-tip strong {
    color: #a78bfa;
    font-weight: 600;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
    .settings-menu {
        min-width: 300px;
        max-width: calc(100vw - 40px);
        right: -10px;
    }
    
    .settings-button-wrapper {
        margin-left: 8px;
    }
}

/* Animation for menu appearance */
@keyframes settingsMenuSlideIn {
    from {
        opacity: 0;
        transform: translateY(-12px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.settings-menu.active {
    animation: settingsMenuSlideIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Hover glow effect */
.settings-icon-btn::after {
    content: '';
    position: absolute;
    inset: -4px;
    background: radial-gradient(circle, rgba(167, 139, 250, 0.3), transparent);
    opacity: 0;
    transition: opacity 0.3s ease;
    border-radius: 16px;
    z-index: -1;
}

.settings-icon-btn:hover::after {
    opacity: 1;
}

/* Ensure menu stays above other content */
.settings-menu {
    isolation: isolate;
}