:root {
    --pos-x: 50%;
    --pos-y: 40%;
    --ui-width: 600px;
    --ui-scale: 1;
    --ui-active-opacity: 1;
    --ui-idle-opacity: 0.5; 
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; user-select: none; -webkit-user-drag: none; }
input[type="text"], input[type="password"], textarea, input[type="number"], select, input[type="file"] { user-select: auto; -webkit-user-drag: auto; }

body, html { width: 100%; height: 100%; overflow: hidden; background: linear-gradient(135deg, #202124 0%, #2b2d31 100%); }

.bg-layer { 
    position: fixed; 
    top: 0; left: 0; 
    width: 100vw; height: 100vh; 
    background-size: cover; 
    background-position: center; 
    background-repeat: no-repeat;
    transition: opacity 1.2s ease-in-out; 
    will-change: opacity, background-image; 
}

#bg-active { z-index: 1; }
#bg-next { z-index: 2; }

body::before { content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.25); z-index: 3; pointer-events: none; }

#main-container { 
    position: absolute; left: var(--pos-x); top: var(--pos-y); 
    transform: translate(-50%, -50%) scale(var(--ui-scale)); 
    width: var(--ui-width); max-width: 90vw; z-index: 10; 
    transition: opacity 0.6s ease-in-out; 
    opacity: var(--ui-active-opacity);
}

#main-container.idle-state {
    opacity: var(--ui-idle-opacity);
}

.search-wrapper { display: flex; background: rgba(255, 255, 255, 0.85); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-radius: 30px; padding: 5px; box-shadow: 0 8px 32px rgba(0,0,0,0.2); }
#engine-selector { border: none; background: transparent; padding: 0 15px; font-size: 16px; outline: none; cursor: pointer; border-right: 1px solid #ccc; }
#search-input { flex: 1; border: none; background: transparent; padding: 15px 20px; font-size: 18px; outline: none; }
#search-btn { border: none; background: #0078D7; color: white; padding: 0 25px; border-radius: 25px; font-size: 16px; cursor: pointer; transition: background 0.2s; white-space: nowrap; }
#search-btn:hover { background: #005a9e; }

/* AI 搜索建议框 */
#search-suggestions { position: absolute; top: 100%; left: 0; right: 0; margin-top: 15px; background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-radius: 20px; box-shadow: 0 8px 32px rgba(0,0,0,0.2); overflow: hidden; display: flex; flex-direction: column; z-index: 20; opacity: 0; transform: translateY(-10px); pointer-events: none; transition: opacity 0.3s, transform 0.3s; }
#search-suggestions.visible { opacity: 1; transform: translateY(0); pointer-events: auto; }
.suggestion-item { padding: 14px 25px; font-size: 16px; cursor: pointer; color: #444; transition: background 0.2s, color 0.2s; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-bottom: 1px solid rgba(0,0,0,0.04); }
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover { background: #0078D7; color: #fff; }
.suggestion-item.loading { color: #888; cursor: default; background: transparent; font-style: italic; }
.suggestion-item.loading:hover { background: transparent; color: #888; }

/* 右下角设置按钮区 */
#settings-trigger-zone { position: fixed; bottom: 0; right: 0; width: 150px; height: 150px; z-index: 98; }
#settings-toggle { opacity: 0; position: fixed; bottom: 20px; right: 20px; background: rgba(255, 255, 255, 0.8); border: none; border-radius: 50%; width: 45px; height: 45px; font-size: 22px; cursor: pointer; z-index: 100; transition: transform 0.3s, opacity 0.5s; pointer-events: none; transform: scale(0.5); }
#settings-toggle:hover { transform: rotate(90deg) scale(1); }
#settings-toggle.visible { opacity: 1; pointer-events: auto; transform: scale(1); }

/* 右上角保存按钮区 */
#save-trigger-zone { position: fixed; top: 0; right: 0; width: 150px; height: 150px; z-index: 98; }
#save-btn { opacity: 0; position: fixed; top: 20px; right: 20px; background: rgba(255, 255, 255, 0.8); border: none; border-radius: 50%; width: 45px; height: 45px; font-size: 22px; cursor: pointer; z-index: 100; transition: transform 0.3s, opacity 0.5s; pointer-events: none; transform: scale(0.5); }
#save-btn:hover { transform: scale(1.15); } 
#save-btn.visible { opacity: 1; pointer-events: auto; transform: scale(1); } 

#settings-panel { position: fixed; bottom: 80px; right: 20px; width: 340px; max-height: 85vh; overflow-y: auto; background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(10px); padding: 20px; border-radius: 15px; box-shadow: 0 10px 30px rgba(0,0,0,0.3); z-index: 101; transition: opacity 0.3s, transform 0.3s; transform-origin: bottom right; }
#settings-panel.hidden { opacity: 0; pointer-events: none; transform: scale(0.9); }
#settings-panel h3 { margin-bottom: 10px; font-size: 16px; color: #222; border-bottom: 1px solid #ddd; padding-bottom: 5px; }
.setting-group { margin-bottom: 15px; background: rgba(0,0,0,0.03); padding: 10px; border-radius: 8px; }
#settings-panel label { display: block; margin-top: 8px; font-size: 13px; color: #555; }
#settings-panel input, #settings-panel textarea, #settings-panel select { width: 100%; margin-top: 5px; font-size: 13px; padding: 4px; border: 1px solid #ccc; border-radius: 4px; background: #fff; }
#settings-panel textarea { resize: vertical; }

.flex-row { display: flex; gap: 5px; margin-top: 5px; }
.flex-row input[type="text"] { flex: 1; margin-top: 0; }
button.btn-primary { flex: 1; padding: 6px 10px; background: #0078D7; color: white; border: none; border-radius: 6px; font-size: 13px; cursor: pointer; transition: background 0.2s; white-space: nowrap; }
button.btn-primary:hover { background: #005a9e; }
button.btn-danger { width: 100%; padding: 10px; background: #ff4d4f; color: white; border: none; border-radius: 8px; cursor: pointer; }
button.btn-danger:hover { background: #d9363e; }

/* ================= 移动端 (手机) 深度适配 ================= */
@media (max-width: 768px) {
    #main-container {
        width: 92vw !important;
        transform: translate(-50%, -50%) scale(1) !important;
    }
    
    .search-wrapper {
        padding: 3px;
        border-radius: 25px;
    }

    #engine-selector {
        padding: 0 10px;
        font-size: 14px;
        max-width: 85px;
    }

    #search-input {
        padding: 12px 10px;
        font-size: 16px; 
    }

    #search-btn {
        padding: 0 18px;
        font-size: 14px;
    }

    #settings-panel {
        width: 90vw;
        right: 5vw;
        bottom: 75px;
        padding: 15px;
        max-height: 75vh;
    }

    /* 手机端按钮恢复自动隐藏机制，只调整位置 */
    #settings-toggle {
        bottom: 15px; right: 15px;
    }
    
    #save-btn {
        top: 15px; right: 15px; bottom: auto;
    }

    #settings-trigger-zone, #save-trigger-zone {
        display: none;
    }
}

/* ================= 底部备案栏 ================= */
#beian-footer {
    position: fixed;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.55);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
    white-space: nowrap;
    pointer-events: auto;
    transition: opacity 0.3s;
}

#beian-footer a {
    color: rgba(255, 255, 255, 0.55);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

#beian-footer a:hover {
    color: rgba(255, 255, 255, 0.85);
    text-decoration: underline;
}

.beian-divider {
    color: rgba(255, 255, 255, 0.3);
    user-select: none;
}

.beian-icon {
    width: 14px;
    height: 14px;
    vertical-align: middle;
    flex-shrink: 0;
}

/* 移动端适配 */
@media (max-width: 600px) {
    #beian-footer {
        font-size: 10px;
        gap: 4px;
        bottom: 4px;
        flex-wrap: wrap;
        justify-content: center;
    }
    .beian-icon {
        width: 12px;
        height: 12px;
    }
}